1
1
# Lint levels
2
2
3
- In ` rustc ` , lints are divided into four * levels* :
3
+ In ` rustc ` , lints are divided into five * levels* :
4
4
5
5
1 . allow
6
6
2 . warn
7
- 3 . deny
8
- 4 . forbid
7
+ 3 . force-warn
8
+ 4 . deny
9
+ 5 . forbid
9
10
10
11
Each lint has a default level (explained in the lint listing later in this
11
12
chapter), and the compiler has a default warning level. First, let's explain
@@ -57,6 +58,14 @@ warning: unused variable: `x`
57
58
= note: to avoid this warning, consider using ` _x` instead
58
59
```
59
60
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
+
60
69
## deny
61
70
62
71
A 'deny' lint produces an error if you violate it. For example, this code
@@ -87,11 +96,12 @@ This lint level gives you that.
87
96
88
97
# # forbid
89
98
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
95
105
warn.
96
106
97
107
# # Configuring warning levels
@@ -113,8 +123,8 @@ certain lint levels. We'll talk about that last.
113
123
114
124
### Via compiler flag
115
125
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:
118
128
119
129
```bash
120
130
$ 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:
158
168
$ rustc lib.rs --crate-type=lib -D missing-docs -D unused-variables
159
169
```
160
170
161
- And of course, you can mix these four flags together:
171
+ And of course, you can mix these five flags together:
162
172
163
173
```bash
164
174
$ 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
176
186
$ rustc lib.rs --crate-type=lib -D unused -A unused-variables
177
187
```
178
188
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
+
179
193
### Via an attribute
180
194
181
195
You can also modify the lint level with a crate-wide attribute:
@@ -207,7 +221,8 @@ warning: missing documentation for a function
207
221
| ^^^^^^^^^^^^
208
222
```
209
223
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.
211
226
212
227
You can also pass in multiple lints per attribute:
213
228
0 commit comments