Skip to content

Commit 228a5f4

Browse files
Document force-warn
Co-authored-by: Mark Rousskov <[email protected]>
1 parent aee2c30 commit 228a5f4

File tree

2 files changed

+27
-33
lines changed

2 files changed

+27
-33
lines changed

Diff for: src/doc/rustc/src/lints/levels.md

+27-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Lint levels
22

3-
In `rustc`, lints are divided into four *levels*:
3+
In `rustc`, lints are divided into five *levels*:
44

55
1. allow
66
2. warn
7-
3. deny
8-
4. forbid
7+
3. force-warn
8+
4. deny
9+
5. forbid
910

1011
Each lint has a default level (explained in the lint listing later in this
1112
chapter), and the compiler has a default warning level. First, let's explain
@@ -57,6 +58,14 @@ warning: unused variable: `x`
5758
= note: to avoid this warning, consider using `_x` instead
5859
```
5960

61+
## force-warn
62+
63+
'force-warn' is a special lint level. It's the same as 'warn' in that a lint
64+
at this level will produce a warning, but unlike the 'warn' level, the
65+
'force-warn' level cannot be overridden. If a lint is set to 'force-warn', it
66+
is guaranteed to warn: no more, no less. This is true even if the overall lint
67+
level is capped via cap-lints.
68+
6069
## deny
6170

6271
A 'deny' lint produces an error if you violate it. For example, this code
@@ -87,11 +96,12 @@ This lint level gives you that.
8796

8897
## forbid
8998

90-
'forbid' is a special lint level that's stronger than 'deny'. It's the same
91-
as 'deny' in that a lint at this level will produce an error, but unlike the
92-
'deny' level, the 'forbid' level can not be overridden to be anything lower
93-
than an error. However, lint levels may still be capped with `--cap-lints`
94-
(see below) so `rustc --cap-lints warn` will make lints set to 'forbid' just
99+
'forbid' is a special lint level that fills the same role for 'deny' that
100+
'force-warn' does for 'warn'. It's the same as 'deny' in that a lint at this
101+
level will produce an error, but unlike the 'deny' level, the 'forbid' level
102+
can not be overridden to be anything lower than an error. However, lint
103+
levels may still be capped with `--cap-lints` (see below) so `rustc --cap-
104+
lints warn` will make lints set to 'forbid' just
95105
warn.
96106

97107
## Configuring warning levels
@@ -113,8 +123,8 @@ certain lint levels. We'll talk about that last.
113123
114124
### Via compiler flag
115125
116-
The `-A`, `-W`, `-D`, and `-F` flags let you turn one or more lints
117-
into allowed, warning, deny, or forbid levels, like this:
126+
The `-A`, `-W`, `--force-warn` `-D`, and `-F` flags let you turn one or more lints
127+
into allowed, warning, force-warn, deny, or forbid levels, like this:
118128
119129
```bash
120130
$ rustc lib.rs --crate-type=lib -W missing-docs
@@ -158,7 +168,7 @@ You can also pass each flag more than once for changing multiple lints:
158168
$ rustc lib.rs --crate-type=lib -D missing-docs -D unused-variables
159169
```
160170
161-
And of course, you can mix these four flags together:
171+
And of course, you can mix these five flags together:
162172
163173
```bash
164174
$ rustc lib.rs --crate-type=lib -D missing-docs -A unused-variables
@@ -176,6 +186,10 @@ You can make use of this behavior by overriding the level of one specific lint o
176186
$ rustc lib.rs --crate-type=lib -D unused -A unused-variables
177187
```
178188
189+
Since `force-warn` and `forbid` cannot be overridden, setting
190+
one of them will prevent any later level for the same lint from
191+
taking effect.
192+
179193
### Via an attribute
180194
181195
You can also modify the lint level with a crate-wide attribute:
@@ -207,7 +221,8 @@ warning: missing documentation for a function
207221
| ^^^^^^^^^^^^
208222
```
209223
210-
All four, `warn`, `allow`, `deny`, and `forbid` all work this way.
224+
`warn`, `allow`, `deny`, and `forbid` all work this way. There is
225+
no way to set a lint to `force-warn` using an attribute.
211226
212227
You can also pass in multiple lints per attribute:
213228

Diff for: src/doc/unstable-book/src/compiler-flags/force-warn.md

-21
This file was deleted.

0 commit comments

Comments
 (0)