Skip to content

Commit

Permalink
Add help to allow lint for the implied by suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
Urgau committed Sep 4, 2023
1 parent eba5b44 commit efbe445
Show file tree
Hide file tree
Showing 16 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions compiler/rustc_middle/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,9 @@ pub fn explain_lint_level_source(
err.note_once(format!(
"`{flag} {hyphen_case_lint_name}` implied by `{flag} {hyphen_case_flag_val}`"
));
err.help_once(format!(
"to override `{flag} {hyphen_case_flag_val}` add `#[allow({name})]`"
));
}
}
LintLevelSource::Node { name: lint_attr_name, span, reason, .. } => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ LL | fn lintme() { }
| ^^^^^^^^^^^^^^^
|
= note: `-D test-lint` implied by `-D lint-me`
= help: to override `-D lint-me` add `#[allow(test_lint)]`

error: item is named 'pleaselintme'
--> $DIR/lint-group-plugin-deny-cmdline.rs:12:1
Expand All @@ -21,6 +22,7 @@ LL | fn pleaselintme() { }
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D please-lint` implied by `-D lint-me`
= help: to override `-D lint-me` add `#[allow(please_lint)]`

error: aborting due to 2 previous errors; 1 warning emitted

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ LL | arg: NotIntoDiagnosticArg,
|
= help: normalized in stderr
note: required by a bound in `Diagnostic::set_arg`
--> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:960:5
--> $COMPILER_DIR/rustc_errors/src/diagnostic.rs:968:5

error: aborting due to 2 previous errors

Expand Down
1 change: 1 addition & 0 deletions tests/ui/derive-uninhabited-enum-38885.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +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)]`

warning: 1 warning emitted

1 change: 1 addition & 0 deletions tests/ui/lint-group-forbid-always-trumps-cli.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `-F unused-variables` implied by `-F unused`
= help: to override `-F unused` add `#[allow(unused_variables)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui/lint/command-line-lint-group-deny.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let _InappropriateCamelCasing = true;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
|
= note: `-D non-snake-case` implied by `-D bad-style`
= help: to override `-D bad-style` add `#[allow(non_snake_case)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui/lint/command-line-lint-group-forbid.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let _InappropriateCamelCasing = true;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
|
= note: `-F non-snake-case` implied by `-F bad-style`
= help: to override `-F bad-style` add `#[allow(non_snake_case)]`

error: aborting due to previous error

1 change: 1 addition & 0 deletions tests/ui/lint/command-line-lint-group-warn.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | let _InappropriateCamelCasing = true;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: convert the identifier to snake case: `_inappropriate_camel_casing`
|
= note: `-W non-snake-case` implied by `-W bad-style`
= help: to override `-W bad-style` add `#[allow(non_snake_case)]`

warning: 1 warning emitted

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

warning: 1 warning emitted

1 change: 1 addition & 0 deletions tests/ui/lint/force-warn/lint-group-allow-warnings.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ LL | pub fn FUNCTION() {}
| ^^^^^^^^ help: convert the identifier to snake case: `function`
|
= note: `--force-warn non-snake-case` implied by `--force-warn nonstandard-style`
= help: to override `--force-warn nonstandard-style` add `#[allow(non_snake_case)]`

warning: 1 warning emitted

Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | pub fn function(_x: Box<SomeTrait>) {}
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2021!
= note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/warnings-promoted-to-error.html>
= note: `--force-warn bare-trait-objects` implied by `--force-warn rust-2018-idioms`
= help: to override `--force-warn rust-2018-idioms` add `#[allow(bare_trait_objects)]`
help: use `dyn`
|
LL | pub fn function(_x: Box<dyn SomeTrait>) {}
Expand Down
1 change: 1 addition & 0 deletions tests/ui/lint/future-incompat-test.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `-A unused-variables` implied by `-A unused`
= help: to override `-A unused` add `#[allow(unused_variables)]`

1 change: 1 addition & 0 deletions tests/ui/lint/lint-pre-expansion-extern-module.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ LL | pub fn try() {}
= warning: this is accepted in the current edition (Rust 2015) but is a hard error in Rust 2018!
= note: for more information, see issue #49716 <https://github.com/rust-lang/rust/issues/49716>
= note: `-W keyword-idents` implied by `-W rust-2018-compatibility`
= help: to override `-W rust-2018-compatibility` add `#[allow(keyword_idents)]`

warning: 1 warning emitted

1 change: 1 addition & 0 deletions tests/ui/macros/must-use-in-macro-55516.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ LL | write!(&mut example, "{}", 42);
|
= note: this `Result` may be an `Err` variant, which should be handled
= note: `-W unused-must-use` implied by `-W unused`
= help: to override `-W unused` add `#[allow(unused_must_use)]`
= note: this warning originates in the macro `write` (in Nightly builds, run with -Z macro-backtrace for more info)

warning: 1 warning emitted
Expand Down

0 comments on commit efbe445

Please sign in to comment.