compiler/middle/lint: Suggest #[expect(dead_code)] as alternative to #[allow(dead_code)]

This commit is contained in:
Tobias Bieniek 2025-10-15 09:36:04 +02:00
parent 4d43e78082
commit 86cef2ff98
No known key found for this signature in database
3 changed files with 12 additions and 5 deletions

View file

@ -265,9 +265,16 @@ fn explain_lint_level_source(
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
));
if matches!(orig_level, Level::Warn | Level::Deny) {
err.help_once(format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
));
let help = if name == "dead_code" {
format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[expect({name})]` or `#[allow({name})]`"
)
} else {
format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
)
};
err.help_once(help);
}
}
}

View file

@ -9,7 +9,7 @@ LL | Void(Void),
|
= note: `Foo` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
= note: `-W dead-code` implied by `-W unused`
= help: to override `-W unused` add `#[allow(dead_code)]`
= help: to override `-W unused` add `#[expect(dead_code)]` or `#[allow(dead_code)]`
warning: 1 warning emitted

View file

@ -5,7 +5,7 @@ LL | fn foo() -> &'static str {
| ^^^
|
= note: `-W dead-code` implied by `-W unused`
= help: to override `-W unused` add `#[allow(dead_code)]`
= help: to override `-W unused` add `#[expect(dead_code)]` or `#[allow(dead_code)]`
warning: 1 warning emitted