mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
70d1c586ce
don't suggest non-deriveable traits for unions Fixes rust-lang/rust#137587 Before, the compiler suggested adding `#[derive(Debug)]` (other traits too) for unions, which is misleading because some traits can't be automatically derived. Only traits that are still suggested are Copy and Clone. I noticed the error label changed after removing the suggestion. I hope this isn't a big deal, but let me know if that's an issue. original example: ```rs union Union { member: usize, } impl PartialEq<u8> for Union { fn eq(&self, rhs: &u8) -> bool { unsafe { self.member == (*rhs).into() } } } fn main() { assert_eq!(Union { member: 0 }, 0); } ``` before: ``` error[E0277]: `Union` doesn't implement `Debug` --> src\main.rs:13:5 | 13 | assert_eq!(Union { member: 0 }, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Debug` is not implemented for `Union` | = note: add `#[derive(Debug)]` to `Union` or manually `impl Debug for Union` = note: this error originates in the macro `assert_eq` (in Nightly builds, run with -Z macro-backtrace for more info) help: consider annotating `Union` with `#[derive(Debug)]` | 2 + #[derive(Debug)] 3 | union Union { | ``` after (the message doesn't suggest adding #[derive(Debug)] to unions) ``` error[E0277]: `Union` doesn't implement `Debug` --> src\main.rs:13:5 | 13 | assert_eq!(Union { member: 0 }, 0); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unsatisfied trait bound | help: the trait `Debug` is not implemented for `Union` --> src\main.rs:2:1 | 2 | union Union { | ^^^^^^^^^^^ = note: manually `impl Debug for Union` ```