Skip to content
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

rustc_session: forbid lints override regardless of position #70918

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/doc/rustc/src/lints/levels.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ The order of these command line arguments is taken into account. The following a
$ rustc lib.rs --crate-type=lib -D unused-variables -A unused-variables
```

You can make use of this behavior by overriding the level of one specific lint out of a group of lints. The following example denies all the lints in the `unused` group, but explicitly allows the `unused-variables` lint in that group:
You can make use of this behavior by overriding the level of one specific lint out of a group of lints. The following example denies all the lints in the `unused` group, but explicitly allows the `unused-variables` lint in that group (forbid still trumps everything regardless of ordering):

```bash
$ rustc lib.rs --crate-type=lib -D unused -A unused-variables
Expand Down
8 changes: 7 additions & 1 deletion src/librustc_session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,13 @@ pub fn get_cmd_lint_options(
let mut describe_lints = false;

for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
for (passed_arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
let arg_pos = if let lint::Forbid = level {
// forbid is always specified last, so it can't be overridden
usize::max_value()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, this could be usize::MAX now. :)

} else {
passed_arg_pos
};
if lint_name == "help" {
describe_lints = true;
} else {
Expand Down
7 changes: 7 additions & 0 deletions src/test/ui-fulldeps/lint-group-forbid-always-trumps-cli.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// aux-build:lint-group-plugin-test.rs
// compile-flags: -F unused -A unused

fn main() {
let x = 1;
//~^ ERROR unused variable: `x`
}
10 changes: 10 additions & 0 deletions src/test/ui-fulldeps/lint-group-forbid-always-trumps-cli.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: unused variable: `x`
--> $DIR/lint-group-forbid-always-trumps-cli.rs:5:9
|
LL | let x = 1;
| ^ help: if this is intentional, prefix it with an underscore: `_x`
|
= note: `-F unused-variables` implied by `-F unused`

error: aborting due to previous error