about summary refs log tree commit diff
path: root/src/test/ui/deriving
AgeCommit message (Collapse)AuthorLines
2023-01-11Move /src/test to /testsAlbert Larsan-3111/+0
2022-12-13Make some diagnostics not depend on the source of what they reference being ↵Oli Scherer-3/+0
available
2022-11-30Fix ICE from #105101Jacob Pratt-0/+38
2022-11-21Streamline deriving on packed structs.Nicholas Nethercote-17/+6
The current approach to field accesses in derived code: - Normal case: `&self.0` - In a packed struct that derives `Copy`: `&{self.0}` - In a packed struct that doesn't derive `Copy`: `let Self(ref x) = *self` The `let` pattern used in the third case is equivalent to the simpler field access in the first case. This commit changes the third case to use a field access. The commit also combines two boolean arguments (`is_packed` and `always_copy`) into a single field (`copy_fields`) earlier, to save passing both around.
2022-10-19Rollup merge of #103176 - nnethercote:fix-TyKind-is_simple_path, r=spastorinoMatthias Krüger-3/+49
Fix `TyKind::is_simple_path` Fixes #103157. r? `@spastorino`
2022-10-18Fix `TyKind::is_simple_path`.Nicholas Nethercote-0/+44
PR #98758 introduced code to avoid redundant assertions in derived code like this: ``` let _: ::core::clone::AssertParamIsClone<u32>; let _: ::core::clone::AssertParamIsClone<u32>; ``` But the predicate `is_simple_path` introduced as part of this failed to account for generic arguments. Therefore the deriving code erroneously considers types like `Option<bool>` and `Option<f32>` to be the same. This commit fixes `is_simple_path`. Fixes #103157.
2022-10-18Tweak `deriving-all-codegen.rs`.Nicholas Nethercote-3/+5
To include some `Option<>` fields of different types in a single enum. The test output is currently buggy, but the next commit will fix that.
2022-10-16Rollup merge of #103089 - cjgillot:automatic-structural-eq, r=oli-obkMatthias Krüger-24/+48
Mark derived StructuralEq as automatically derived. Fixes https://github.com/rust-lang/rust/issues/69952 Drive-by: use correct spans for generic params.
2022-10-15Mark derived StructuralEq as automatically derived.Camille GILLOT-24/+48
2022-10-09Add a regression test for #39137Ben Kimock-0/+20
2022-10-03Rollup merge of #101040 - ↵Matthias Krüger-0/+10
danielhenrymantilla:no-bounds-for-default-annotated-derive, r=joshtriplett Fix `#[derive(Default)]` on a generic `#[default]` enum adding unnecessary `Default` bounds That is, given something like: ```rs // #[default] on a generic enum does not add `Default` bounds to the type params. #[derive(Default)] enum MyOption<T> { #[default] None, Some(T), } ``` then `MyOption<T> : Default`_as currently implemented_ only holds when `T : Default`, as reported by ```@5225225``` [over Zulip](https://rust-lang.zulipchat.com/#narrow/stream/122651-general/topic/.23.5Bderive.28Default.29.5D.20for.20enums.20with.20fields). This is contrary to [what the accepted RFC proposes](https://rust-lang.github.io/rfcs/3107-derive-default-enum.html#generated-bounds) (_i.e._, that `T` be allowed not to be itself `Default`), and indeed seems to be a rather unnecessary limitation.
2022-09-05Add corresponding regression testDaniel Henry-Mantilla-0/+10
2022-08-30Stabilize GATsJack Huey-2/+0
2022-08-18Auto merge of #98655 - nnethercote:dont-derive-PartialEq-ne, r=dtolnaybors-57/+0
Don't derive `PartialEq::ne`. Currently we skip deriving `PartialEq::ne` for C-like (fieldless) enums and empty structs, thus reyling on the default `ne`. This behaviour is unnecessarily conservative, because the `PartialEq` docs say this: > Implementations must ensure that eq and ne are consistent with each other: > > `a != b` if and only if `!(a == b)` (ensured by the default > implementation). This means that the default implementation (`!(a == b)`) is always good enough. So this commit changes things such that `ne` is never derived. The motivation for this change is that not deriving `ne` reduces compile times and binary sizes. Observable behaviour may change if a user has defined a type `A` with an inconsistent `PartialEq` and then defines a type `B` that contains an `A` and also derives `PartialEq`. Such code is already buggy and preserving bug-for-bug compatibility isn't necessary. Two side-effects of the change: - There is only one error message produced for types where `PartialEq` cannot be derived, instead of two. - For coverage reports, some warnings about generated `ne` methods not being executed have disappeared. Both side-effects seem fine, and possibly preferable.
2022-08-03Warn about dead tuple struct fieldsFabian Wolff-1/+3
2022-08-01Don't derive `PartialEq::ne`.Nicholas Nethercote-57/+0
Currently we skip deriving `PartialEq::ne` for C-like (fieldless) enums and empty structs, thus reyling on the default `ne`. This behaviour is unnecessarily conservative, because the `PartialEq` docs say this: > Implementations must ensure that eq and ne are consistent with each other: > > `a != b` if and only if `!(a == b)` (ensured by the default > implementation). This means that the default implementation (`!(a == b)`) is always good enough. So this commit changes things such that `ne` is never derived. The motivation for this change is that not deriving `ne` reduces compile times and binary sizes. Observable behaviour may change if a user has defined a type `A` with an inconsistent `PartialEq` and then defines a type `B` that contains an `A` and also derives `PartialEq`. Such code is already buggy and preserving bug-for-bug compatibility isn't necessary. Two side-effects of the change: - There is only one error message produced for types where `PartialEq` cannot be derived, instead of two. - For coverage reports, some warnings about generated `ne` methods not being executed have disappeared. Both side-effects seem fine, and possibly preferable.
2022-07-19Remove #[allow(unused_qualifications)] lines from derive diff testMichael Holloway-99/+0
2022-07-13Use `&{self.x}` for packed `Copy` structs.Nicholas Nethercote-20/+6
Because it's more concise than the `let` form.
2022-07-11Handle tags better.Nicholas Nethercote-118/+78
Currently, for the enums and comparison traits we always check the tag for equality before doing anything else. This is a bit clumsy. This commit changes things so that the tags are handled very much like a zeroth field in the enum. For `eq`/ne` this makes the code slightly cleaner. For `partial_cmp` and `cmp` it's a more notable change: in the case where the tags aren't equal, instead of having a tag equality check followed by a tag comparison, it just does a single tag comparison. The commit also improves how `Hash` works for enums: instead of having duplicated code to hash the tag for every arm within the match, we do it just once before the match. All this required replacing the `EnumNonMatchingCollapsed` value with a new `EnumTag` value. For fieldless enums the new code is particularly improved. All the code now produced is close to optimal, being very similar to what you'd write by hand.
2022-07-11Avoid some unnecessary blocks in derive output.Nicholas Nethercote-9/+6
2022-07-11Rename tag-related things.Nicholas Nethercote-90/+89
Use `tag` in names of things referring to tags, instead of the mysterious `vi`. Also change `arg_N` in output to `argN`, which has the same length as `self` and so results in nicer vertical alignments.
2022-07-11Remove unnecessary `&*` sigil pairs in derived code.Nicholas Nethercote-42/+37
By producing `&T` expressions for fields instead of `T`. This matches what the existing comments (e.g. on `FieldInfo`) claim is happening, and it's also what most of the trait-specific code needs. The exception is `PartialEq`, which needs `T` expressions for lots of special case error messaging to work. So we now convert the `&T` back to a `T` for `PartialEq`.
2022-07-11Remove unnecessary sigils and `ref`s in derived code.Nicholas Nethercote-107/+105
E.g. improving code like this: ``` match &*self { &Enum1::Single { x: ref __self_0 } => { ::core::hash::Hash::hash(&*__self_0, state) } } ``` to this: ``` match self { Enum1::Single { x: __self_0 } => { ::core::hash::Hash::hash(&*__self_0, state) } } ``` by removing the `&*`, the `&`, and the `ref`. I suspect the current generated code predates deref-coercion. The commit also gets rid of `use_temporaries`, instead passing around `always_copy`, which makes things a little clearer. And it fixes up some comments.
2022-07-11Add a fieldless enum with one variant to `deriving-all-codegen.rs`.Nicholas Nethercote-0/+81
Because the generated code is different to fieldless enum with multiple variants.
2022-07-11Add a non-`Copy` packed struct to `deriving-all-codegen.rs`.Nicholas Nethercote-22/+124
Because the generatedd code is different to a `Copy` packed struct.
2022-07-11Add a struct with an unsized field to the `deriving-all-codegen.rs` test.Nicholas Nethercote-1/+60
It's an interesting case, requiring the use of `&&` in `Debug::fmt`.
2022-07-05Avoid the unnecessary innermost match in `partial_cmp`/`cmp`.Nicholas Nethercote-105/+23
We currently do a match on the comparison of every field in a struct or enum variant. But the last field has a degenerate match like this: ``` match ::core::cmp::Ord::cmp(&self.y, &other.y) { ::core::cmp::Ordering::Equal => ::core::cmp::Ordering::Equal, cmp => cmp, }, ``` This commit changes it to this: ``` ::core::cmp::Ord::cmp(&self.y, &other.y), ``` This is fairly straightforward thanks to the existing `cs_fold1` function. The commit also removes the `cs_fold` function which is no longer used. (Note: there is some repetition now in `cs_cmp` and `cs_partial_cmp`. I will remove that in a follow-up PR.)
2022-07-04Avoid unnecessary 1-tuples in derived code.Nicholas Nethercote-31/+31
2022-07-04Don't repeat `AssertParamIs{Clone,Eq}` assertions.Nicholas Nethercote-13/+0
It's common to see repeated assertions like this in derived `clone` and `eq` methods: ``` let _: ::core::clone::AssertParamIsClone<u32>; let _: ::core::clone::AssertParamIsClone<u32>; ``` This commit avoids them.
2022-07-04Avoid unnecessary blocks in derive output.Nicholas Nethercote-316/+260
By not committing to either block form or expression form until necessary, we can avoid lots of unnecessary blocks.
2022-07-04Add 0-variant and 1-variant enums to the `deriving-all-codegen.rs` test.Nicholas Nethercote-0/+176
Because they are interesting cases with their own code generation paths.
2022-07-04Add a union to the `deriving-all-codegen.rs` test.Nicholas Nethercote-0/+26
Because `derive(Clone)` on unions triggers special behaviour.
2022-07-04Don't use match-destructuring for derived ops on structs.Nicholas Nethercote-358/+173
All derive ops currently use match-destructuring to access fields. This is reasonable for enums, but sub-optimal for structs. E.g.: ``` fn eq(&self, other: &Point) -> bool { match *other { Self { x: ref __self_1_0, y: ref __self_1_1 } => match *self { Self { x: ref __self_0_0, y: ref __self_0_1 } => (*__self_0_0) == (*__self_1_0) && (*__self_0_1) == (*__self_1_1), }, } } ``` This commit changes derive ops on structs to use field access instead, e.g.: ``` fn eq(&self, other: &Point) -> bool { self.x == other.x && self.y == other.y } ``` This is faster to compile, results in smaller binaries, and is simpler to generate. Unfortunately, we have to keep the old pattern generating code around for `repr(packed)` structs because something like `&self.x` (which doesn't show up in `PartialEq` ops, but does show up in `Debug` and `Hash` ops) isn't allowed. But this commit at least changes those cases to use let-destructuring instead of match-destructuring, e.g.: ``` fn hash<__H: ::core::hash::Hasher>(&self, state: &mut __H) -> () { { let Self(ref __self_0_0) = *self; { ::core::hash::Hash::hash(&(*__self_0_0), state) } } } ``` There are some unnecessary blocks remaining in the generated code, but I will fix them in a follow-up PR.
2022-07-04Add an interesting case to the `deriving-all-codegen.rs` test.Nicholas Nethercote-2/+114
2022-06-27Improve derived discriminant testing.Nicholas Nethercote-11/+11
Currently the generated code for methods like `eq`, `ne`, and `partial_cmp` includes stuff like this: ``` let __self_vi = ::core::intrinsics::discriminant_value(&*self); let __arg_1_vi = ::core::intrinsics::discriminant_value(&*other); if true && __self_vi == __arg_1_vi { ... } ``` This commit removes the unnecessary `true &&`, and makes the generating code a little easier to read in the process. It also fixes some errors in comments.
2022-06-27Add a test checking the output of builtin derives.Nicholas Nethercote-0/+1163
2022-06-21Move some tests to more reasonable directoriesCaio-0/+11
2022-04-07Stabilize `derive_default_enum`Jacob Pratt-3/+0
2022-02-12Update chalk testsMatthew Jasper-1/+0
2021-11-06Move some tests to more reasonable directoriesCaio-0/+644
2021-10-02Expand one test (from jackh726)Audun Halland-2/+4
2021-09-29Additional tests (from jackh726)Audun Halland-0/+23
2021-09-29Deriving: Include bound generic params for extracted type parameters in ↵Audun Halland-0/+14
where clause
2021-09-26Remove box syntax from most places in src/test outside of the issues direst31-2/+0
2021-09-15Move some tests to more reasonable directoriesCaio-0/+13
2021-09-09Ignore automatically derived impls of `Clone` and `Debug` in dead code analysisFabian Wolff-0/+9
2021-07-27Permit deriving default on enums with `#[default]`Jacob Pratt-2/+22
2021-07-13expand: Support helper attributes for built-in derive macrosVadim Petrochenkov-0/+36
2020-10-06Update to chalk 0.31. Implement some unimplemented. Ignore some tests in ↵Jack Huey-0/+1
compare mode chalk don't finish.
2020-05-01SipHasher::new() is literally with SipHasher with both keys being 0Hanif Bin Ariffin-1/+1