-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Disallow later override of forbid lint in same scope #73379
Closed
pnkfelix
wants to merge
4
commits into
rust-lang:master
from
pnkfelix:issue-70819-disallow-override-forbid-in-same-scope
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e24aa73
rewrite old test so that its attributes are consistent with what we w…
pnkfelix 01e8e9f
When building lint specs map for a given scope, check if forbid prese…
pnkfelix ef03a5d
Regression test.
pnkfelix 4ec4c4f
review suggestion: use existing defn rather than new intern call
pnkfelix File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// This test is checking that you cannot override a `forbid` by adding in other | ||
// attributes later in the same scope. (We already ensure that you cannot | ||
// override it in nested scopes). | ||
|
||
// If you turn off deduplicate diagnostics (which rustc turns on by default but | ||
// compiletest turns off when it runs ui tests), then the errors are | ||
// (unfortunately) repeated here because the checking is done as we read in the | ||
// errors, and curretly that happens two or three different times, depending on | ||
// compiler flags. | ||
// | ||
// I decided avoiding the redundant output was not worth the time in engineering | ||
// effort for bug like this, which 1. end users are unlikely to run into in the | ||
// first place, and 2. they won't see the redundant output anyway. | ||
|
||
// compile-flags: -Z deduplicate-diagnostics=yes | ||
|
||
fn forbid_first(num: i32) -> i32 { | ||
#![forbid(unused)] | ||
#![deny(unused)] | ||
//~^ ERROR: deny(unused) incompatible with previous forbid in same scope [E0453] | ||
#![warn(unused)] | ||
//~^ ERROR: warn(unused) incompatible with previous forbid in same scope [E0453] | ||
#![allow(unused)] | ||
//~^ ERROR: allow(unused) incompatible with previous forbid in same scope [E0453] | ||
|
||
num * num | ||
} | ||
|
||
fn forbid_last(num: i32) -> i32 { | ||
#![deny(unused)] | ||
#![warn(unused)] | ||
#![allow(unused)] | ||
#![forbid(unused)] | ||
|
||
num * num | ||
} | ||
|
||
fn forbid_multiple(num: i32) -> i32 { | ||
#![forbid(unused)] | ||
#![forbid(unused)] | ||
|
||
num * num | ||
} | ||
|
||
fn main() { | ||
forbid_first(10); | ||
forbid_last(10); | ||
forbid_multiple(10); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/test/ui/lint/issue-70819-dont-override-forbid-in-same-scope.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
error[E0453]: deny(unused) incompatible with previous forbid in same scope | ||
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:19:13 | ||
| | ||
LL | #![forbid(unused)] | ||
| ------ `forbid` level set here | ||
LL | #![deny(unused)] | ||
| ^^^^^^ | ||
|
||
error[E0453]: warn(unused) incompatible with previous forbid in same scope | ||
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:21:13 | ||
| | ||
LL | #![forbid(unused)] | ||
| ------ `forbid` level set here | ||
... | ||
LL | #![warn(unused)] | ||
| ^^^^^^ | ||
|
||
error[E0453]: allow(unused) incompatible with previous forbid in same scope | ||
--> $DIR/issue-70819-dont-override-forbid-in-same-scope.rs:23:14 | ||
| | ||
LL | #![forbid(unused)] | ||
| ------ `forbid` level set here | ||
... | ||
LL | #![allow(unused)] | ||
| ^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0453`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Interesting, so it is a hard error now to have
forbid
and something else on the same scope, but not in a nested scope?I guess I don't care very strongly, just didn't expect this. I expected the same behavior was for nested scopes. Also I think this is inconsistent with command-line handling (where
-F lint -A lint
works, but the-A
has no effect).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 your comment.
It is a hard error, today, to have a forbid on one scope and something else in a nested scope. (AIUI, that's the whole point of forbid, versus deny).
For example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=63cb51c86b8b1c15a8b22f132ce6c32e
Can you show me an example of what current behavior of forbid that you think I should be modelling instead? (In source code, that is; lets leave aside the semantics of command line argument parsing. where I think it is more justifiable to let
-F
silently override-A
.)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.
Oops, somehow I thought
forbid
would overwrite laterallow
, I did not know that it makes them an error. Never mind then. I think my only comment for this PR then is that it would be nice to share the code that emits that error -- if the error is pre-existing; the wording is slightly different now.I feel command-line arguments should be consistent with lint attributes though.
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.
The problem with making command line arguments "consistent" with lint attributes, from my point of view, is that I think a lot of tools do inject (or freely mix) new command line arguments, and so I think users run into combinations of
-F
and-A
on a single command line a lot more often than they run into#[forbid]
and#[allow]
in a single source item.A hard error for mixing
-F
and-A
when they arose due to e.g. makefile variables is really annoying for end users.(I suppose the analogy for source code items would be macro expansion, right? Does one see
#[allow]
getting injected from macros very often? I can admit this has crossed my mind at times, especially back when I put in thepush_unsafe
/pop_unsafe
hacks five years ago ...)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.
Indeed I'd argue that for the same reasons, a hard error could be annoying for the attributes. But then nobody complaining about it for five years is a good argument for it not being very annoying.^^