Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,9 @@ 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) {
let suggestion = if name == "dead_code" { "expect" } else { "allow" };
Copy link
Member Author

Choose a reason for hiding this comment

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

I scoped this to only the dead_code suggestion for now. It might make sense to extend it to others in the future too though.

err.help_once(format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
"to override `{flag} {hyphen_case_flag_val}` add `#[{suggestion}({name})]`"
));
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/derives/derive-debug-uninhabited-enum.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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)]`

warning: 1 warning emitted

8 changes: 8 additions & 0 deletions tests/ui/lint/dead-code/unused-fn-with-check-pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//@ check-pass
//@ compile-flags: -Wunused

fn foo() -> &'static str { //~ WARN function `foo` is never used
"hello"
}

fn main() {}
11 changes: 11 additions & 0 deletions tests/ui/lint/dead-code/unused-fn-with-check-pass.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
warning: function `foo` is never used
--> $DIR/unused-fn-with-check-pass.rs:4:4
|
LL | fn foo() -> &'static str {
| ^^^
|
= note: `-W dead-code` implied by `-W unused`
= help: to override `-W unused` add `#[expect(dead_code)]`

warning: 1 warning emitted

Loading