Skip to content

Commit 09052a6

Browse files
authored
Rollup merge of #70918 - tobithiel:fix_forbid_override, r=davidtwco
rustc_session: forbid lints override regardless of position Addresses the regression reported in #70819 for command line arguments, but does not address the source code flag regression.
2 parents 4f00396 + f03db79 commit 09052a6

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

src/doc/rustc/src/lints/levels.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ The order of these command line arguments is taken into account. The following a
170170
$ rustc lib.rs --crate-type=lib -D unused-variables -A unused-variables
171171
```
172172
173-
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:
173+
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):
174174
175175
```bash
176176
$ rustc lib.rs --crate-type=lib -D unused -A unused-variables

src/librustc_session/config.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1017,7 +1017,13 @@ pub fn get_cmd_lint_options(
10171017
let mut describe_lints = false;
10181018

10191019
for &level in &[lint::Allow, lint::Warn, lint::Deny, lint::Forbid] {
1020-
for (arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
1020+
for (passed_arg_pos, lint_name) in matches.opt_strs_pos(level.as_str()) {
1021+
let arg_pos = if let lint::Forbid = level {
1022+
// forbid is always specified last, so it can't be overridden
1023+
usize::max_value()
1024+
} else {
1025+
passed_arg_pos
1026+
};
10211027
if lint_name == "help" {
10221028
describe_lints = true;
10231029
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// aux-build:lint-group-plugin-test.rs
2+
// compile-flags: -F unused -A unused
3+
4+
fn main() {
5+
let x = 1;
6+
//~^ ERROR unused variable: `x`
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: unused variable: `x`
2+
--> $DIR/lint-group-forbid-always-trumps-cli.rs:5:9
3+
|
4+
LL | let x = 1;
5+
| ^ help: if this is intentional, prefix it with an underscore: `_x`
6+
|
7+
= note: `-F unused-variables` implied by `-F unused`
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)