-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Support overriding warnings
level for a specific lint via command line
#113307
Support overriding warnings
level for a specific lint via command line
#113307
Conversation
r? @oli-obk (rustbot has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
a4866f8
to
390a7d2
Compare
390a7d2
to
8f096a2
Compare
@rfcbot merge This seems like the right interpretation of what the user was asking for if they wrote The only concern I see is that it's different from |
Team member @oli-obk has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns: Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
#[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 comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how this work.
In this case in-source annotations take priority over command line option, but above (#[warn(non_snake_case)]
) command line takes priority over in-source annotation.
Also, what -A warnings
means exactly
- allow all lints (not true according to this test)
- allow lints with default level
warn
- allow lints with effective level
warn
(explicit level with fallback to default)
?
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.
In this case in-source annotations take priority over command line option, but above (
#[warn(non_snake_case)]
) command line takes priority over in-source annotation.
The warnings
lint and -A warnings
is... special. To the best of my knowedge, -A warnings
suppresses warn level lints even when there is a source code annotation for the specific non-warnings
lint (of warn level). However, when there is a #[level(warnings)]
source code annotation, it overrides -A warnings
for the lexical scope affected by the annotation.
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.
Also, lints with levels higher than warn
are not affected by -A warnings
or #[allow(warnings)]
at all, such as deny-level lints.
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.
I have 2 reservations.
- If we are accepting this PR, I'd recommend taking the opportunity to have something fully consistent with how lints and lint groups are handled right now:
- command line arguments are order sensitive, so
-Awarning -Wlint
is different from-Wlint -Awarnings
- attributes nest:
#[allow(warnings)]
should mark all lints that have levelWarn
at that point and mark them asAllow
.
@rfcbot concern nesting
- I'm not really fond of the implementation. Would it be possible to move this special case in
rustc_lint::levels
? For instance, when thewarnings
pseudo-group is encountered, walk all the currently-warning lints to change their level?
{ | ||
if matches!(warnings_src, LintLevelSource::CommandLine(..)) | ||
&& lint != LintId::of(builtin::WARNINGS) | ||
&& let (Some(lint_level), lint_src) = probe_for_lint_level(lint) |
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
and src
arguments to the current function. We shouldn't recompute them.
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 comment
The 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?
What about -Wdead-code -Awarnings
?
I'm not really fond of the implementation myself either. I will investigate how to make this less hacky. I don't really like the "filter based on |
I am actually very confused myself, if we're at the node corresponding to @rustbot label: +I-lang-nominated |
The first question is: what does "warnings" denote?
In your example, supposing both lints are warn by default, the lint level stack looks like this:
If the lints are not warn-by-default, the behaviour of both interpretations diverge. |
@rfcbot fcp reviewed (I did not review the code, but the high-level interpretation of the flag combination makes a ton of sense to me) |
@rfcbot concern nesting |
We discussed this in the @rust-lang/lang meeting. @jieyouxu unfortunately we do not seem to have a very clear place where we have documented our intentions, although I recall us having many discussions on the topic over the years. My recollection of related decisions is as follows:
I would really like to see this written into the reference, the current section doesn't seem very clear. Two conclusions from the above:
|
In case it got buried in the text, can you clarify this point...
|
Sorry for the late reply. I believe I wanted to ask that if the command line indeed forms the root of the tree, or if it actually overrides the source annotations. |
NestingI think the command line (specifically That's almost all the expressive power one could want along this axis. One wrinkle is that
|
I strongly agree with the suggestion to keep the current behavior because users are relying on it. I will close this PR now. |
Supports the use case to
This PR allows the user to refine the more general
warnings
level specified on the command line with a more specific level for a particular lint.Closes #105104.