don't suggest non-deriveable traits for unions#154118
don't suggest non-deriveable traits for unions#154118rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
|
Some changes occurred in compiler/rustc_attr_parsing |
|
rustbot has assigned @dingxiangfei2009. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Can you please add a test to reflect new behaviour |
8fd2da8 to
ccaae21
Compare
compiler/rustc_trait_selection/src/error_reporting/traits/on_unimplemented.rs
Outdated
Show resolved
Hide resolved
|
Reminder, once the PR becomes ready for a review, use |
|
cc @mejrs |
ccaae21 to
dd844f3
Compare
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
Outdated
Show resolved
Hide resolved
compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs
Outdated
Show resolved
Hide resolved
This comment has been minimized.
This comment has been minimized.
|
I forgot to rebless the test. Will do that in a sec |
dd844f3 to
927e225
Compare
Interesting. I hadn't realized it does this with keywords. It does that with other keywords too. #[diagnostic::on_unimplemented(message = "{impl}")]
trait Baz{}Do note that It at least is consistent: fn main(){
println!("{impl} {union}")
}so I suppose we should leave it this way. |
Don't suggest non-deriveable traits for unions. This also adds enum, struct and union markers to rustc_on_unimplemented
927e225 to
27212bb
Compare
|
It is a bit weird the |
|
@bors r+ rollup |
…for-unions, r=JonathanBrouwer don't suggest non-deriveable traits for unions cc rust-lang#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` ```
|
@malezjaa For in the future, if you put "Fixes #..." rather than "CC #..." it will automatically close the issue :) |
|
Thank you both for the help with this PR :D |
…uwer Rollup of 6 pull requests Successful merges: - #154154 (Emit fewer errors for incorrect rtn and `=` -> `:` typos in bindings) - #154155 (tests/ui/async-await/drop-option-future.rs: New regression test) - #146961 (Allow passing `expr` metavariable as `cfg` predicate) - #154118 (don't suggest non-deriveable traits for unions) - #154120 (Start migrating `DecorateDiagCompat::Builtin` items to `DecorateDiagCompat::Dynamic`) - #154156 (Moving issue-52049 to borrowck)
…uwer Rollup of 6 pull requests Successful merges: - #154154 (Emit fewer errors for incorrect rtn and `=` -> `:` typos in bindings) - #154155 (tests/ui/async-await/drop-option-future.rs: New regression test) - #146961 (Allow passing `expr` metavariable as `cfg` predicate) - #154118 (don't suggest non-deriveable traits for unions) - #154120 (Start migrating `DecorateDiagCompat::Builtin` items to `DecorateDiagCompat::Dynamic`) - #154156 (Moving issue-52049 to borrowck)

Fixes #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:
before:
after (the message doesn't suggest adding #[derive(Debug)] to unions)