1
1
# Diagnostic attributes
2
2
3
- r[ attributes.diagnostic ]
3
+ r[ attributes.diagnostics ]
4
4
5
5
The following [ attributes] are used for controlling or generating diagnostic
6
6
messages during compilation.
7
7
8
8
## Lint check attributes
9
9
10
- r[ attributes.diagnostic .lint]
10
+ r[ attributes.diagnostics .lint]
11
11
12
12
A lint check names a potentially undesirable coding pattern, such as
13
13
unreachable code or omitted documentation.
14
14
15
- r[ attributes.diagnostic .lint.level]
15
+ r[ attributes.diagnostics .lint.level]
16
16
The lint attributes ` allow ` ,
17
17
` expect ` , ` warn ` , ` deny ` , and ` forbid ` use the [ _ MetaListPaths_ ] syntax
18
18
to specify a list of lint names to change the lint level for the entity
19
19
to which the attribute applies.
20
20
21
21
For any lint check ` C ` :
22
22
23
- r[ attributes.diagnostic .lint.allow]
23
+ r[ attributes.diagnostics .lint.allow]
24
24
* ` #[allow(C)] ` overrides the check for ` C ` so that violations will go
25
25
unreported.
26
26
27
- r[ attributes.diagnostic .lint.expect]
27
+ r[ attributes.diagnostics .lint.expect]
28
28
* ` #[expect(C)] ` indicates that lint ` C ` is expected to be emitted. The
29
29
attribute will suppress the emission of ` C ` or issue a warning, if the
30
30
expectation is unfulfilled.
31
31
32
- r[ attributes.diagnostic .lint.warn]
32
+ r[ attributes.diagnostics .lint.warn]
33
33
* ` #[warn(C)] ` warns about violations of ` C ` but continues compilation.
34
34
35
- r[ attributes.diagnostic .lint.deny]
35
+ r[ attributes.diagnostics .lint.deny]
36
36
* ` #[deny(C)] ` signals an error after encountering a violation of ` C ` ,
37
37
38
- r[ attributes.diagnostic .lint.forbid]
38
+ r[ attributes.diagnostics .lint.forbid]
39
39
* ` #[forbid(C)] ` is the same as ` deny(C) ` , but also forbids changing the lint
40
40
level afterwards,
41
41
@@ -58,7 +58,7 @@ pub mod m1 {
58
58
}
59
59
```
60
60
61
- r[ attributes.diagnostic .lint.override]
61
+ r[ attributes.diagnostics .lint.override]
62
62
Lint attributes can override the level specified from a previous attribute, as
63
63
long as the level does not attempt to change a forbidden lint
64
64
(except for ` deny ` , which is allowed inside a ` forbid ` context, but ignored).
@@ -106,7 +106,7 @@ pub mod m3 {
106
106
107
107
### Lint Reasons
108
108
109
- r[ attributes.diagnostic .lint.reason]
109
+ r[ attributes.diagnostics .lint.reason]
110
110
All lint attributes support an additional ` reason ` parameter, to give context why
111
111
a certain attribute was added. This reason will be displayed as part of the lint
112
112
message if the lint is emitted at the defined level.
@@ -143,9 +143,9 @@ pub fn get_path() -> PathBuf {
143
143
144
144
### The ` #[expect] ` attribute
145
145
146
- r[ attributes.diagnostic .expect]
146
+ r[ attributes.diagnostics .expect]
147
147
148
- r[ attributes.diagnostic .expect.intro]
148
+ r[ attributes.diagnostics .expect.intro]
149
149
The ` #[expect(C)] ` attribute creates a lint expectation for lint ` C ` . The
150
150
expectation will be fulfilled, if a ` #[warn(C)] ` attribute at the same location
151
151
would result in a lint emission. If the expectation is unfulfilled, because
@@ -171,7 +171,7 @@ fn main() {
171
171
}
172
172
```
173
173
174
- r[ attributes.lints .expect.fulfillment]
174
+ r[ attributes.diagnostics .expect.fulfillment]
175
175
The lint expectation is only fulfilled by lint emissions which have been suppressed by
176
176
the ` expect ` attribute. If the lint level is modified in the scope with other level
177
177
attributes like ` allow ` or ` warn ` , the lint emission will be handled accordingly and the
@@ -201,7 +201,7 @@ fn select_song() {
201
201
}
202
202
```
203
203
204
- r[ attributes.diagnostic .expect.independent]
204
+ r[ attributes.diagnostics .expect.independent]
205
205
If the ` expect ` attribute contains several lints, each one is expected separately. For a
206
206
lint group it's enough if one lint inside the group has been emitted:
207
207
@@ -230,7 +230,7 @@ pub fn another_example() {
230
230
231
231
### Lint groups
232
232
233
- r[ attributes.diagnostic .lint.group]
233
+ r[ attributes.diagnostics .lint.group]
234
234
Lints may be organized into named groups so that the level of related lints
235
235
can be adjusted together. Using a named group is equivalent to listing out the
236
236
lints within that group.
@@ -251,7 +251,7 @@ fn example() {
251
251
}
252
252
```
253
253
254
- r[ attributes.diagnostic .lint.group.warnings]
254
+ r[ attributes.diagnostics .lint.group.warnings]
255
255
There is a special group named "warnings" which includes all lints at the
256
256
"warn" level. The "warnings" group ignores attribute order and applies to all
257
257
lints that would otherwise warn within the entity.
@@ -271,13 +271,13 @@ fn example_err() {
271
271
272
272
### Tool lint attributes
273
273
274
- r[ attributes.diagnostic .lint.tool]
274
+ r[ attributes.diagnostics .lint.tool]
275
275
276
- r[ attributes.diagnostic .lint.tool.intro]
276
+ r[ attributes.diagnostics .lint.tool.intro]
277
277
Tool lints allows using scoped lints, to ` allow ` , ` warn ` , ` deny ` or ` forbid `
278
278
lints of certain tools.
279
279
280
- r[ attributes.diagnostic .lint.tool.activation]
280
+ r[ attributes.diagnostics .lint.tool.activation]
281
281
Tool lints only get checked when the associated tool is active. If a lint
282
282
attribute, such as ` allow ` , references a nonexistent tool lint, the compiler
283
283
will not warn about the nonexistent lint until you use the tool.
@@ -305,14 +305,14 @@ fn foo() {
305
305
306
306
## The ` deprecated ` attribute
307
307
308
- r[ attributes.diagnostic .deprecated]
308
+ r[ attributes.diagnostics .deprecated]
309
309
310
- r[ attributes.diagnostic .deprecated.intro]
310
+ r[ attributes.diagnostics .deprecated.intro]
311
311
The * ` deprecated ` attribute* marks an item as deprecated. ` rustc ` will issue
312
312
warnings on usage of ` #[deprecated] ` items. ` rustdoc ` will show item
313
313
deprecation, including the ` since ` version and ` note ` , if available.
314
314
315
- r[ attributes.diagnostic .deprecated.syntax]
315
+ r[ attributes.diagnostics .deprecated.syntax]
316
316
The ` deprecated ` attribute has several forms:
317
317
318
318
- ` deprecated ` --- Issues a generic message.
@@ -352,23 +352,23 @@ The [RFC][1270-deprecation.md] contains motivations and more details.
352
352
353
353
## The ` must_use ` attribute
354
354
355
- r[ attributes.diagnostic .must_use]
355
+ r[ attributes.diagnostics .must_use]
356
356
357
- r[ attributes.diagnostic .must_use.intro]
357
+ r[ attributes.diagnostics .must_use.intro]
358
358
The * ` must_use ` attribute* is used to issue a diagnostic warning when a value
359
359
is not "used".
360
360
361
- r[ attributes.diagnostic .must_use.allowed-positions]
361
+ r[ attributes.diagnostics .must_use.allowed-positions]
362
362
The ` must_use ` attribute can be applied to user-defined composite types
363
363
([ ` struct ` s] [ struct ] , [ ` enum ` s] [ enum ] , and [ ` union ` s] [ union ] ), [ functions] ,
364
364
and [ traits] .
365
365
366
- r[ attributes.diagnostic .must_use.message]
366
+ r[ attributes.diagnostics .must_use.message]
367
367
The ` must_use ` attribute may include a message by using the
368
368
[ _ MetaNameValueStr_ ] syntax such as ` #[must_use = "example message"] ` . The
369
369
message will be given alongside the warning.
370
370
371
- r[ attributes.diagnostic .must_use.type]
371
+ r[ attributes.diagnostics .must_use.type]
372
372
When used on user-defined composite types, if the [ expression] of an
373
373
[ expression statement] has that type, then the ` unused_must_use ` lint is
374
374
violated.
@@ -387,7 +387,7 @@ struct MustUse {
387
387
MustUse :: new ();
388
388
```
389
389
390
- r[ attributes.diagnostic .must_use.fn]
390
+ r[ attributes.diagnostics .must_use.fn]
391
391
When used on a function, if the [ expression] of an [ expression statement] is a
392
392
[ call expression] to that function, then the ` unused_must_use ` lint is
393
393
violated.
@@ -400,7 +400,7 @@ fn five() -> i32 { 5i32 }
400
400
five ();
401
401
```
402
402
403
- r[ attributes.diagnostic .must_use.trait]
403
+ r[ attributes.diagnostics .must_use.trait]
404
404
When used on a [ trait declaration] , a [ call expression] of an [ expression
405
405
statement] to a function that returns an [ impl trait] or a [ dyn trait] of that trait violates
406
406
the ` unused_must_use ` lint.
@@ -418,7 +418,7 @@ fn get_critical() -> impl Critical {
418
418
get_critical ();
419
419
```
420
420
421
- r[ attributes.diagnostic .must_use.trait-function]
421
+ r[ attributes.diagnostics .must_use.trait-function]
422
422
When used on a function in a trait declaration, then the behavior also applies
423
423
when the call expression is a function from an implementation of the trait.
424
424
@@ -436,7 +436,7 @@ impl Trait for i32 {
436
436
5i32 . use_me ();
437
437
```
438
438
439
- r[ attributes.diagnostic .must_use.trait-impl-function]
439
+ r[ attributes.diagnostics .must_use.trait-impl-function]
440
440
When used on a function in a trait implementation, the attribute does nothing.
441
441
442
442
> Note: Trivial no-op expressions containing the value will not violate the
0 commit comments