Avoid redundant note when a #[derive] is already suggested#157126
Avoid redundant note when a #[derive] is already suggested#157126Dnreikronos wants to merge 1 commit into
Conversation
The `#[rustc_on_unimplemented]` note on `Debug` ("add `#[derive(Debug)]`
to `X` or manually `impl Debug for X`") duplicates the `consider
annotating X with #[derive(..)]` suggestion emitted by `suggest_derive`.
Skip the note when that suggestion will be shown, and keep it otherwise
so types whose derive can't be suggested (e.g. a field isn't `Debug`)
still get actionable guidance.
|
r? @adwinwhite rustbot has assigned @adwinwhite. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| if derive_suggestion_will_be_shown { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
It makes more sense to not enter into the loop if every element will be skipped if a condition is true. The way it is written we're just wasting time iterating over every element in order to do nothing.
There was a problem hiding this comment.
Just to confirm, what is the difference between the output in this PR and the output if we remove the following lines? Are there some cases where the note is useful? It'd be a good idea to include that context in the comment or at least in this PR.
rust/library/core/src/fmt/mod.rs
Lines 1039 to 1043 in 6368fd5
Fixes #157118
The
Debug#[rustc_on_unimplemented]note ("add#[derive(Debug)]toXor manuallyimpl Debug for X") repeats theconsider annotating X with #[derive(..)]suggestion thatsuggest_derivealready emits, so it's just noise on these bound errors.Now the note is dropped whenever that derive suggestion will be shown, and kept otherwise so a type that can't be auto-derived (say one of its fields isn't
Debug) still gets the hint.