Skip to content

Emit only one note per struct when multiple fields would trigger the same compiler note #97643

Description

@bruxisma

Given the following code:

#[derive(Debug)]
pub struct Whatever {
  pub field0: (),
  field1: (),
  field2: (),
  field3: (),
  field4: (),
}

The current output is:

warning: field is never read: `field1`
  --> src\cmake\preset.rs:23:3
   |
23 |   field1: (),
   |   ^^^^^^^^^^
   |
note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  --> src\cmake\preset.rs:20:10
   |
20 | #[derive(Debug)]
   |          ^^^^^
   = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: field is never read: `field2`
  --> src\cmake\preset.rs:24:3
   |
24 |   field2: (),
   |   ^^^^^^^^^^
   |
note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  --> src\cmake\preset.rs:20:10
   |
20 | #[derive(Debug)]
   |          ^^^^^
   = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: field is never read: `field3`
  --> src\cmake\preset.rs:25:3
   |
25 |   field3: (),
   |   ^^^^^^^^^^
   |
note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  --> src\cmake\preset.rs:20:10
   |
20 | #[derive(Debug)]
   |          ^^^^^
   = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: field is never read: `field4`
  --> src\cmake\preset.rs:26:3
   |
26 |   field4: (),
   |   ^^^^^^^^^^
   |
note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  --> src\cmake\preset.rs:20:10
   |
20 | #[derive(Debug)]
   |          ^^^^^
   = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

Ideally the output should look like:

warning: field is never read: `field1`
  --> src\cmake\preset.rs:23:3
   |
23 |   field1: (),
   |   ^^^^^^^^^^
   |

warning: field is never read: `field2`
  --> src\cmake\preset.rs:24:3
   |
24 |   field2: (),
   |   ^^^^^^^^^^
   |

warning: field is never read: `field3`
  --> src\cmake\preset.rs:25:3
   |
25 |   field3: (),
   |   ^^^^^^^^^^
   |

warning: field is never read: `field4`
  --> src\cmake\preset.rs:26:3
   |
26 |   field4: (),
   |   ^^^^^^^^^^
   |
note: `Whatever` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  --> src\cmake\preset.rs:20:10
   |
20 | #[derive(Debug)]
   |          ^^^^^
   = note: this warning originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info)

Or something even more compact if possible. Without this, compiler output is almost double, and mostly unnecessary.

Activity

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

Metadata

Metadata

Assignees

Labels

A-diagnosticsArea: Messages for errors, warnings, and lintsD-verboseDiagnostics: Too much output caused by a single piece of incorrect code.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions