-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Support overriding warnings
level for a specific lint via command line
#113307
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -75,7 +75,7 @@ pub fn reveal_actual_level( | |
src: &mut LintLevelSource, | ||
sess: &Session, | ||
lint: LintId, | ||
probe_for_lint_level: impl FnOnce(LintId) -> (Option<Level>, LintLevelSource), | ||
probe_for_lint_level: impl Fn(LintId) -> (Option<Level>, LintLevelSource), | ||
) -> Level { | ||
// If `level` is none then we actually assume the default level for this lint. | ||
let mut level = level.unwrap_or_else(|| lint.lint.default_level(sess.edition())); | ||
|
@@ -90,8 +90,20 @@ pub fn reveal_actual_level( | |
// future compatibility warning. | ||
if level == Level::Warn && lint != LintId::of(FORBIDDEN_LINT_GROUPS) { | ||
let (warnings_level, warnings_src) = probe_for_lint_level(LintId::of(builtin::WARNINGS)); | ||
if let Some(configured_warning_level) = warnings_level { | ||
if configured_warning_level != Level::Warn { | ||
if let Some(configured_warning_level) = warnings_level | ||
&& configured_warning_level != Level::Warn | ||
{ | ||
if matches!(warnings_src, LintLevelSource::CommandLine(..)) | ||
&& lint != LintId::of(builtin::WARNINGS) | ||
&& let (Some(lint_level), lint_src) = probe_for_lint_level(lint) | ||
&& matches!(lint_src, LintLevelSource::CommandLine(..)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we care about the order in which the command line arguments are passed? |
||
{ | ||
// We have a command-line `-Awarnings` *and* a command-line e.g. `-Wspecific-lint`. | ||
// Let's have the `specific-lint`'s command-line level override the command-line | ||
// `warnings` level. | ||
level = lint_level; | ||
*src = lint_src; | ||
} else { | ||
level = configured_warning_level; | ||
*src = warnings_src; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// compile-flags: -A warnings | ||
|
||
fn main() { | ||
// This will be overriden by the `-A warnings` command line option. | ||
#[warn(non_snake_case)] | ||
let _OwO = 0u8; | ||
|
||
// But this should not. | ||
#[deny(non_snake_case)] | ||
let _UwU = 0u8; | ||
//~^ ERROR variable `_UwU` should have a snake case name | ||
|
||
bar(); | ||
baz(); | ||
} | ||
|
||
#[warn(warnings)] | ||
fn bar() { | ||
let _OwO = 0u8; | ||
//~^ WARN variable `_OwO` should have a snake case name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand how this work. Also, what
? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, lints with levels higher than |
||
} | ||
|
||
#[deny(warnings)] | ||
fn baz() { | ||
let _OwO = 0u8; | ||
//~^ ERROR variable `_OwO` should have a snake case name | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error: variable `_UwU` should have a snake case name | ||
--> $DIR/command-line-allow-warnings.rs:10:9 | ||
| | ||
LL | let _UwU = 0u8; | ||
| ^^^^ help: convert the identifier to snake case: `_uw_u` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/command-line-allow-warnings.rs:9:12 | ||
| | ||
LL | #[deny(non_snake_case)] | ||
| ^^^^^^^^^^^^^^ | ||
|
||
warning: variable `_OwO` should have a snake case name | ||
--> $DIR/command-line-allow-warnings.rs:19:9 | ||
| | ||
LL | let _OwO = 0u8; | ||
| ^^^^ help: convert the identifier to snake case: `_ow_o` | ||
| | ||
= note: `#[warn(non_snake_case)]` on by default | ||
|
||
error: variable `_OwO` should have a snake case name | ||
--> $DIR/command-line-allow-warnings.rs:25:9 | ||
| | ||
LL | let _OwO = 0u8; | ||
| ^^^^ help: convert the identifier to snake case: `_ow_o` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/command-line-allow-warnings.rs:23:8 | ||
| | ||
LL | #[deny(warnings)] | ||
| ^^^^^^^^ | ||
= note: `#[deny(non_snake_case)]` implied by `#[deny(warnings)]` | ||
|
||
error: aborting due to 2 previous errors; 1 warning emitted | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// compile-flags: -A warnings -W unused-variables | ||
oli-obk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
fn main() { | ||
let x = 0u8; | ||
//~^ WARNING unused variable | ||
|
||
// Source code lint level should override command-line lint level in any case. | ||
#[deny(unused_variables)] | ||
let y = 0u8; | ||
//~^ ERROR unused variable | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
warning: unused variable: `x` | ||
--> $DIR/command-line-lint-level-specific-lint.rs:4:9 | ||
| | ||
LL | let x = 0u8; | ||
| ^ help: if this is intentional, prefix it with an underscore: `_x` | ||
| | ||
= note: requested on the command line with `-W unused-variables` | ||
|
||
error: unused variable: `y` | ||
--> $DIR/command-line-lint-level-specific-lint.rs:9:9 | ||
| | ||
LL | let y = 0u8; | ||
| ^ help: if this is intentional, prefix it with an underscore: `_y` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/command-line-lint-level-specific-lint.rs:8:12 | ||
| | ||
LL | #[deny(unused_variables)] | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error; 1 warning emitted | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those are
level
andsrc
arguments to the current function. We shouldn't recompute them.