Skip to content

Commit bb04e82

Browse files
committed
Doc: clarify priority of lint level sources
This updates the rustc book to clearly document how conflicting lint configurations are resolved across different sources, including command-line flags, crate-level attributes, in-line attributes, and `--cap-lints`. It also explains the special behavior of `forbid` and `force_warn`.
1 parent 449c801 commit bb04e82

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,3 +331,22 @@ $
331331
This feature is used heavily by Cargo; it will pass `--cap-lints allow` when
332332
compiling your dependencies, so that if they have any warnings, they do not
333333
pollute the output of your build.
334+
335+
## Priority of Lint Level Sources
336+
337+
Rust allows setting lint levels (`allow`, `warn`, `deny`, etc.) through various sources: directly in the code, via command-line flags, or through global compiler configuration. When these sources conflict, the compiler follows a well-defined priority order to determine which setting takes effect.
338+
339+
This section explains how Rust resolves conflicts between **different sources of lint configuration**, rather than between the lint levels themselves.
340+
341+
### Priority of Sources (Highest to Lowest)
342+
343+
```
344+
--cap-lints >
345+
in-line attributes (#[...]) >
346+
crate-level attributes (#![...]) >
347+
command-line flags (-A, -W, -D)
348+
```
349+
350+
### Special Cases
351+
352+
The special levels `forbid(lint)` and `force_warn(lint)` take precedence over normal configurations **regardless of where they are set**.

0 commit comments

Comments
 (0)