Skip to content

Commit f92c323

Browse files
authored
Rollup merge of rust-lang#128826 - Alexendoo:lint-override-suggestions, r=compiler-errors
Only suggest `#[allow]` for `--warn` and `--deny` lint level flags `--force-warn` and `--forbid` cannot be overridden
2 parents 40a79e7 + 9289f56 commit f92c323

8 files changed

+5
-10
lines changed

compiler/rustc_middle/src/lint.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,11 @@ pub fn explain_lint_level_source(
228228
err.note_once(format!(
229229
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
230230
));
231-
err.help_once(format!(
232-
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
233-
));
231+
if matches!(orig_level, Level::Warn | Level::Deny) {
232+
err.help_once(format!(
233+
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
234+
));
235+
}
234236
}
235237
}
236238
LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => {

tests/ui/lint/command-line-lint-group-forbid.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | let _InappropriateCamelCasing = true;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
66
|
77
= note: `-F non-snake-case` implied by `-F bad-style`
8-
= help: to override `-F bad-style` add `#[allow(non_snake_case)]`
98

109
error: aborting due to 1 previous error
1110

tests/ui/lint/force-warn/cap-lints-warn-allowed-warn-by-default-lint.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | 0...100 => true,
77
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
88
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
99
= note: `--force-warn ellipsis-inclusive-range-patterns` implied by `--force-warn rust-2021-compatibility`
10-
= help: to override `--force-warn rust-2021-compatibility` add `#[allow(ellipsis_inclusive_range_patterns)]`
1110

1211
warning: 1 warning emitted
1312

tests/ui/lint/force-warn/lint-group-allow-warnings.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | pub fn FUNCTION() {}
55
| ^^^^^^^^ help: convert the identifier to snake case: `function`
66
|
77
= note: `--force-warn non-snake-case` implied by `--force-warn nonstandard-style`
8-
= help: to override `--force-warn nonstandard-style` add `#[allow(non_snake_case)]`
98

109
warning: 1 warning emitted
1110

tests/ui/lint/force-warn/lint-group-allowed-cli-warn-by-default-lint.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
77
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
88
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
99
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
10-
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
1110
help: if this is an object-safe trait, use `dyn`
1211
|
1312
LL | pub fn function(_x: Box<dyn SomeTrait>) {}

tests/ui/lint/force-warn/lint-group-allowed-lint-group.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
77
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
88
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
99
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
10-
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
1110
help: if this is an object-safe trait, use `dyn`
1211
|
1312
LL | pub fn function(_x: Box<dyn SomeTrait>) {}

tests/ui/lint/force-warn/lint-group-allowed-warn-by-default-lint.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
77
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
88
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
99
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
10-
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
1110
help: if this is an object-safe trait, use `dyn`
1211
|
1312
LL | pub fn function(_x: Box<dyn SomeTrait>) {}

tests/ui/lint/group-forbid-always-trumps-cli.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | let x = 1;
55
| ^ help: if this is intentional, prefix it with an underscore: `_x`
66
|
77
= note: `-F unused-variables` implied by `-F unused`
8-
= help: to override `-F unused` add `#[allow(unused_variables)]`
98

109
error: aborting due to 1 previous error
1110

0 commit comments

Comments
 (0)