-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poor diagnostic combining #[derive(Debug)] with #[repr(C, packed)] struct #110777
Comments
This diagnostic is poor, but I'd like to point out that |
This is stripped down from a full example, but you're probably right…it would be enough to use |
Yeah our diagnostics regressed when we fixed #27060, good point. Not sure how we usually handle special diagnostics for |
Also FWIW, the intended fix is to declare The derive macro has to decide whether to take a reference or a copy without having any type information. And for a packed struct, taking a copy seems like the more promising strategy in general, so that's what we do. |
Maybe we could add a |
…ompiler-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 rust-lang#117406 Partially addresses rust-lang#110777
Code
Current output
Desired output
Rationale and extra context
I thought this was a regression in 1.69, and it sort of was, but presumably the old code was incorrect, since you can't form a reference to a field in a
repr(packed)
struct. Nothing in the diagnostic pointed me to that, though, so I had to figure out why this struct was different.Other cases
No response
Anything else?
No response
The text was updated successfully, but these errors were encountered: