Skip to content

Avoid redundant note when a #[derive] is already suggested#157126

Open
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:avoid-redundant-derive-note-on-unimplemented
Open

Avoid redundant note when a #[derive] is already suggested#157126
Dnreikronos wants to merge 1 commit into
rust-lang:mainfrom
Dnreikronos:avoid-redundant-derive-note-on-unimplemented

Conversation

@Dnreikronos
Copy link
Copy Markdown
Contributor

@Dnreikronos Dnreikronos commented May 29, 2026

Fixes #157118

The Debug #[rustc_on_unimplemented] note ("add #[derive(Debug)] to X or manually impl Debug for X") repeats the consider annotating X with #[derive(..)] suggestion that suggest_derive already 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.

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.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 29, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 29, 2026

r? @adwinwhite

rustbot has assigned @adwinwhite.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 17 candidates

Copy link
Copy Markdown
Contributor

@estebank estebank left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to see the results of the change, they certainly were redundant.

View changes since this review

Comment on lines +463 to +465
if derive_suggestion_will_be_shown {
continue;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

on(
all(crate_local, not(Self = "{union}")),
note = "add `#[derive(Debug)]` to `{Self}` or manually `impl {This} for {Self}`"
),
on(all(crate_local, Self = "{union}"), note = "manually `impl {This} for {Self}`"),

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redundant note in some bound errors caused by imperfect derives

4 participants