You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of #67885 - tobithiel:fix_group_lint_allow_override, r=Mark-Simulacrum
rustc_session: allow overriding lint level of individual lints from a group
Fixes#58211 and fixesrust-lang/rust-clippy#4778 and fixesrust-lang/rust-clippy#4091
Instead of hard-coding the lint level preferences (from lowest to highest precedence: `lint::Allow -> lint::Warn -> lint::Deny -> lint::Forbid`), the position of the argument in the command line gets taken into account.
Examples:
1. Passing `-D unused -A unused-variables` denies everything in the lint group `unused` **except** `unused-variables` which is explicitly allowed.
1. Passing `-A unused-variables -D unused` denies everything in the lint group `unused` **including** `unused-variables` since the allow is specified before the deny (and therefore overridden by the deny).
This matches the behavior that is already being used when specifying `allow`/`deny` in the source code.
Copy file name to clipboardexpand all lines: src/doc/rustc/src/command-line-arguments.md
+8
Original file line number
Diff line number
Diff line change
@@ -215,21 +215,29 @@ This controls which [target](targets/index.md) to produce.
215
215
216
216
This flag will set which lints should be set to the [warn level](lints/levels.md#warn).
217
217
218
+
_Note:_ The order of these lint level arguments is taken into account, see [lint level via compiler flag](lints/levels.md#via-compiler-flag) for more information.
219
+
218
220
<aid="option-a-allow"></a>
219
221
## `-A`: set lint allowed
220
222
221
223
This flag will set which lints should be set to the [allow level](lints/levels.md#allow).
222
224
225
+
_Note:_ The order of these lint level arguments is taken into account, see [lint level via compiler flag](lints/levels.md#via-compiler-flag) for more information.
226
+
223
227
<aid="option-d-deny"></a>
224
228
## `-D`: set lint denied
225
229
226
230
This flag will set which lints should be set to the [deny level](lints/levels.md#deny).
227
231
232
+
_Note:_ The order of these lint level arguments is taken into account, see [lint level via compiler flag](lints/levels.md#via-compiler-flag) for more information.
233
+
228
234
<aid="option-f-forbid"></a>
229
235
## `-F`: set lint forbidden
230
236
231
237
This flag will set which lints should be set to the [forbid level](lints/levels.md#forbid).
232
238
239
+
_Note:_ The order of these lint level arguments is taken into account, see [lint level via compiler flag](lints/levels.md#via-compiler-flag) for more information.
Copy file name to clipboardexpand all lines: src/doc/rustc/src/lints/levels.md
+12
Original file line number
Diff line number
Diff line change
@@ -164,6 +164,18 @@ And of course, you can mix these four flags together:
164
164
$ rustc lib.rs --crate-type=lib -D missing-docs -A unused-variables
165
165
```
166
166
167
+
The order of these command line arguments is taken into account. The following allows the `unused-variables` lint, because it is the last argument for that lint:
168
+
169
+
```bash
170
+
$ rustc lib.rs --crate-type=lib -D unused-variables -A unused-variables
171
+
```
172
+
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:
174
+
175
+
```bash
176
+
$ rustc lib.rs --crate-type=lib -D unused -A unused-variables
177
+
```
178
+
167
179
### Via an attribute
168
180
169
181
You can also modify the lint level with a crate-wide attribute:
0 commit comments