-
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
Fix how allow/warn/deny/forbid warnings
is handled
#85298
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
r? @Mark-Simulacrum @pnkfelix (or who else dealt with these issues the last time) |
I don't think this patch can be accepted as-is because it breaks the common (though sort of "incorrect" from first principles in some sense) pattern of specifying I suspect changes here are going to want to go through an RFC or at least some sort of broader consideration (nominating for @rust-lang/lang), because it seems like the design space here is somewhat broad and there is likely some amount of breakage to consider. |
Hmm. I've not read deeply yet, but I will second the motivation: when I saw how the warnings lint was implemented, I was quite surprised, it doesn't really match my expectations. |
☔ The latest upstream changes (presumably #85788) made this pull request unmergeable. Please resolve the merge conflicts. |
c04e204
to
d7c8e1f
Compare
☔ The latest upstream changes (presumably #86311) made this pull request unmergeable. Please resolve the merge conflicts. |
d7c8e1f
to
88ff8f8
Compare
☔ The latest upstream changes (presumably #86009) made this pull request unmergeable. Please resolve the merge conflicts. |
Summary for @rust-lang/lang team meeting:
Example:
|
We discussed this in today's @rust-lang/lang meeting. Several people expected that Others expected that it behaved like a lint group, but still felt that it may not be worth breaking compatibility with existing code and expectations. Based on that, the general consensus was roughly that we should keep the current behavior for We may also want to examine the behavior of |
I was just thinking after the meeting: I think it may be worth deprecating the "warnings" lint group and introducing an alternative. @Mark-Simulacrum mentioned the Personally, I think I would prefer an attribute like #![warnings(deny)] and then a command line like That would seem much clearer to me. We could then deprecate the warnings group and suggest a rewrite when it appears in the code to this new form. That said, I don't want to derail this PR with discussion of that specific idea. The long and short of it is that it seemed clear from the meeting that it is best not to think of "warnings" as a lint group, but rather its own thing. I would prefer that if we go that route, we stick to it. (This is true even though I always thought of it as a group, and I can see some value to having a group, perhaps called |
I definitely think it'd be clearer that way, but the transition cost seems painful for all the people using this in their projects (including on the command line for CI). |
I was assuming we could continue supporting the old forms indefinitely, but provide a lint that would warn ... or, hmm, would that run afoul of our chicken/egg issues that |
This pull request attempts to fix #41941, fix #70819 (the command line part, which is why the issue was reopened), and fix #75668. The current implementation of
warnings
(as in-D warnings
or#[allow(warnings)]
) is "lazy" in thatwarnings
is not considered by the linter until it is about to emit a warning, in which case it checks whether an allow/deny/forbid ofwarnings
is in scope and up-/downgrades the warning accordingly.The problem with this approach is that one can never get an (e.g.)
#![allow(warnings)]
out of scope again except by shadowing it with another#[warn/deny/forbid(warnings)]
; ideally, though, one would also want more fine-grained control, such aswhich compiles without warnings and errors on current nightly but causes a warning with my changes (as one would expect, I would argue).
My solution basically consists of adding a "depth" and "position" to
LintLevelSource
. This way, whenever a warning is about to be issued, we can check the source of the warning and the source of thewarnings
pseudo-lint (if any), and see whether the latter can override the former. For instance, the following causes an error on nightly and a warning with my changes:I've also worked on the command line arguments: Calling
rustc
with-F warnings -A unused
works without errors or warnings on current nightly; with my changes, I get