Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bruxisma opened this issue Jun 2, 2022 · 1 comment · Fixed by #97853
Closed
Assignees
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@bruxisma
Copy link

bruxisma commented Jun 2, 2022

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.

@bruxisma bruxisma added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 2, 2022
@compiler-errors compiler-errors added the D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. label Jun 2, 2022
@TaKO8Ki TaKO8Ki self-assigned this Jun 7, 2022
@dullbananas
Copy link

It should be even more compact, like this:

warning: `Whatever` has fields that are never read
  --> src\cmake\preset.rs:23:3
   |
23 |   field1: (),
   |   ^^^^^^^^^^
24 |   field2: (),
   |   ^^^^^^^^^^
25 |   field3: (),
   |   ^^^^^^^^^^
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-verbose Diagnostics: Too much output caused by a single piece of incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants