]> git.lizzy.rs Git - rust.git/commit
Streamline deriving on packed structs.
authorNicholas Nethercote <n.nethercote@gmail.com>
Mon, 21 Nov 2022 00:48:25 +0000 (11:48 +1100)
committerNicholas Nethercote <n.nethercote@gmail.com>
Mon, 21 Nov 2022 03:07:39 +0000 (14:07 +1100)
commita6e09a19fc20cdf9043e1b856d15170ac0f96511
tree14e738619da822f4b4958d4fa3ba88b406d01cdb
parenta28f3c88e50a77bc2a91889241248c4543854e61
Streamline deriving on packed structs.

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.
compiler/rustc_builtin_macros/src/deriving/generic/mod.rs
src/test/ui/deriving/deriving-all-codegen.stdout