rust/src/test/ui/deriving
Nicholas Nethercote ecc6e95ed4 Don't use match-destructuring for derived ops on structs.
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:#️⃣:Hasher>(&self, state: &mut __H) -> () {
    {
	let Self(ref __self_0_0) = *self;
	{ ::core:#️⃣: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-04 10:48:15 +10:00
..
auxiliary
derive-no-std.rs
derive-partialord-correctness.rs
deriving-all-codegen.rs Add an interesting case to the deriving-all-codegen.rs test. 2022-07-04 10:48:15 +10:00
deriving-all-codegen.stdout Don't use match-destructuring for derived ops on structs. 2022-07-04 10:48:15 +10:00
deriving-associated-types.rs
deriving-bounds.rs
deriving-clone-array.rs
deriving-clone-enum.rs
deriving-clone-generic-enum.rs
deriving-clone-generic-struct.rs
deriving-clone-generic-tuple-struct.rs
deriving-clone-struct.rs
deriving-clone-tuple-struct.rs
deriving-cmp-generic-enum.rs
deriving-cmp-generic-struct-enum.rs
deriving-cmp-generic-struct.rs
deriving-cmp-generic-tuple-struct.rs
deriving-cmp-shortcircuit.rs
deriving-copyclone.rs
deriving-default-box.rs
deriving-default-enum.rs
deriving-enum-single-variant.rs
deriving-eq-ord-boxed-slice.rs
deriving-hash.rs
deriving-in-fn.rs
deriving-in-macro.rs
deriving-meta-multiple.rs
deriving-meta.rs
deriving-self-lifetime-totalord-totaleq.rs
deriving-show-2.rs
deriving-show.rs
deriving-via-extension-c-enum.rs
deriving-via-extension-enum.rs
deriving-via-extension-hash-enum.rs
deriving-via-extension-hash-struct.rs
deriving-via-extension-struct-empty.rs
deriving-via-extension-struct-like-enum-variant.rs
deriving-via-extension-struct-tuple.rs
deriving-via-extension-struct.rs
deriving-via-extension-type-params.rs
deriving-with-helper.rs
deriving-with-repr-packed.rs
issue-3935.rs
issue-6341.rs
issue-19358.rs
issue-58319.rs
issue-89188-gat-hrtb.rs