about summary refs log tree commit diff
path: root/compiler/rustc_parse/src/errors.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-11-07 00:03:53 +0000
committerbors <bors@rust-lang.org>2023-11-07 00:03:53 +0000
commit7b97a5ca8422d1495a8918106d3249aa405812d4 (patch)
tree02d03506b065bbac102dab8793a370042043d4f6 /compiler/rustc_parse/src/errors.rs
parent189d6c71f3bb6c52113b5639a80839791974fd22 (diff)
parent4b3ece475d6e77465a30c8b53d7e1e9e861e4b79 (diff)
downloadrust-7b97a5ca8422d1495a8918106d3249aa405812d4.tar.gz
rust-7b97a5ca8422d1495a8918106d3249aa405812d4.zip
Auto merge of #117511 - gurry:117406-err-packed-structs, r=compiler-errors
Emit explanatory note for move errors in packed struct derives

Derive expansions for packed structs with non-`Copy` fields cause move errors because they prefer copying over borrowing since borrowing the fields of a packed struct can result in unaligned access.

This underlying cause of the errors, however, is not apparent to the user. This PR adds a diagnostic note to make it clear to the user (the new note is on the second last line):

```
tests/ui/derives/deriving-with-repr-packed-move-errors.rs:13:16
   |
12 | #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Default)]
   |          ----- in this derive macro expansion
13 | struct StructA(String);
   |                ^^^^^^ move occurs because `self.0` has type `String`, which does not implement the `Copy` trait
   |
   = note: `#[derive(Debug)]` triggers a move because taking references to the fields of a packed struct is undefined behaviour
   = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)
```

Fixes #117406

Partially addresses #110777
Diffstat (limited to 'compiler/rustc_parse/src/errors.rs')
0 files changed, 0 insertions, 0 deletions