Skip to content

Commit 42fbf9b

Browse files
committed
Add identifier syntax to attributes.diagnostics
1 parent 3b6ebe1 commit 42fbf9b

File tree

1 file changed

+69
-3
lines changed

1 file changed

+69
-3
lines changed

src/attributes/diagnostics.md

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,41 @@
11
# Diagnostic attributes
22

3+
r[attributes.diagnostics]
4+
35
The following [attributes] are used for controlling or generating diagnostic
46
messages during compilation.
57

68
## Lint check attributes
79

10+
r[attributes.diagnostics.lints]
11+
812
A lint check names a potentially undesirable coding pattern, such as
9-
unreachable code or omitted documentation. The lint attributes `allow`,
13+
unreachable code or omitted documentation.
14+
15+
r[attributes.diagnostics.lints.level]
16+
The lint attributes `allow`,
1017
`expect`, `warn`, `deny`, and `forbid` use the [_MetaListPaths_] syntax
1118
to specify a list of lint names to change the lint level for the entity
1219
to which the attribute applies.
1320

1421
For any lint check `C`:
1522

23+
r[attributes.diagnostics.lints.allow]
1624
* `#[allow(C)]` overrides the check for `C` so that violations will go
1725
unreported.
26+
27+
r[attributes.diagnostics.lints.expect]
1828
* `#[expect(C)]` indicates that lint `C` is expected to be emitted. The
1929
attribute will suppress the emission of `C` or issue a warning, if the
2030
expectation is unfulfilled.
31+
32+
r[attributes.diagnostics.lints.warn]
2133
* `#[warn(C)]` warns about violations of `C` but continues compilation.
34+
35+
r[attributes.diagnostics.lints.deny]
2236
* `#[deny(C)]` signals an error after encountering a violation of `C`,
37+
38+
r[attributes.diagnostics.lints.forbid]
2339
* `#[forbid(C)]` is the same as `deny(C)`, but also forbids changing the lint
2440
level afterwards,
2541

@@ -42,6 +58,7 @@ pub mod m1 {
4258
}
4359
```
4460

61+
r[attributes.diagnostics.lints.override]
4562
Lint attributes can override the level specified from a previous attribute, as
4663
long as the level does not attempt to change a forbidden lint
4764
(except for `deny`, which is allowed inside a `forbid` context, but ignored).
@@ -89,6 +106,7 @@ pub mod m3 {
89106
90107
### Lint Reasons
91108

109+
r[attributes.diagnostics.lints.reason]
92110
All lint attributes support an additional `reason` parameter, to give context why
93111
a certain attribute was added. This reason will be displayed as part of the lint
94112
message if the lint is emitted at the defined level.
@@ -125,6 +143,9 @@ pub fn get_path() -> PathBuf {
125143

126144
### The `#[expect]` attribute
127145

146+
r[attributes.diagnostics.expect]
147+
148+
r[attributes.diagnostics.expect.general]
128149
The `#[expect(C)]` attribute creates a lint expectation for lint `C`. The
129150
expectation will be fulfilled, if a `#[warn(C)]` attribute at the same location
130151
would result in a lint emission. If the expectation is unfulfilled, because
@@ -150,6 +171,7 @@ fn main() {
150171
}
151172
```
152173

174+
r[attributes.lints.expect.fulfilment]
153175
The lint expectation is only fulfilled by lint emissions which have been suppressed by
154176
the `expect` attribute. If the lint level is modified in the scope with other level
155177
attributes like `allow` or `warn`, the lint emission will be handled accordingly and the
@@ -179,6 +201,7 @@ fn select_song() {
179201
}
180202
```
181203

204+
r[attributes.diagnostics.expect.independent]
182205
If the `expect` attribute contains several lints, each one is expected separately. For a
183206
lint group it's enough if one lint inside the group has been emitted:
184207

@@ -207,6 +230,7 @@ pub fn another_example() {
207230
208231
### Lint groups
209232

233+
r[attributes.lints.groups]
210234
Lints may be organized into named groups so that the level of related lints
211235
can be adjusted together. Using a named group is equivalent to listing out the
212236
lints within that group.
@@ -227,6 +251,7 @@ fn example() {
227251
}
228252
```
229253

254+
r[attributes.lints.warnings-group]
230255
There is a special group named "warnings" which includes all lints at the
231256
"warn" level. The "warnings" group ignores attribute order and applies to all
232257
lints that would otherwise warn within the entity.
@@ -246,9 +271,13 @@ fn example_err() {
246271

247272
### Tool lint attributes
248273

274+
r[attributes.lints.tools]
275+
276+
r[attributes.lints.tools.general]
249277
Tool lints allows using scoped lints, to `allow`, `warn`, `deny` or `forbid`
250278
lints of certain tools.
251279

280+
r[attributes.lints.tools.activation]
252281
Tool lints only get checked when the associated tool is active. If a lint
253282
attribute, such as `allow`, references a nonexistent tool lint, the compiler
254283
will not warn about the nonexistent lint until you use the tool.
@@ -276,10 +305,14 @@ fn foo() {
276305
277306
## The `deprecated` attribute
278307

308+
r[attributes.diagnostics.deprecated]
309+
310+
r[attributes.diagnostics.deprecated.general]
279311
The *`deprecated` attribute* marks an item as deprecated. `rustc` will issue
280312
warnings on usage of `#[deprecated]` items. `rustdoc` will show item
281313
deprecation, including the `since` version and `note`, if available.
282314

315+
r[attributes.diagnostics.deprectead.syntax]
283316
The `deprecated` attribute has several forms:
284317

285318
- `deprecated` --- Issues a generic message.
@@ -293,6 +326,7 @@ The `deprecated` attribute has several forms:
293326
message. This is typically used to provide an explanation about the
294327
deprecation and preferred alternatives.
295328

329+
r[attributes.diagnostics.deprecated.application]
296330
The `deprecated` attribute may be applied to any [item], [trait item], [enum
297331
variant], [struct field], [external block item], or [macro definition]. It
298332
cannot be applied to [trait implementation items]. When applied to an item
@@ -318,15 +352,20 @@ The [RFC][1270-deprecation.md] contains motivations and more details.
318352

319353
## The `must_use` attribute
320354

355+
r[attributes.diagnostics.must_use]
356+
357+
r[attributes.diagnostics.must_use.application]
321358
The *`must_use` attribute* is used to issue a diagnostic warning when a value
322359
is not "used". It can be applied to user-defined composite types
323360
([`struct`s][struct], [`enum`s][enum], and [`union`s][union]), [functions],
324361
and [traits].
325362

363+
r[attributes.diagnostics.must_use.syntax]
326364
The `must_use` attribute may include a message by using the
327365
[_MetaNameValueStr_] syntax such as `#[must_use = "example message"]`. The
328366
message will be given alongside the warning.
329367

368+
r[attributes.diagnostics.must_use.types]
330369
When used on user-defined composite types, if the [expression] of an
331370
[expression statement] has that type, then the `unused_must_use` lint is
332371
violated.
@@ -345,6 +384,7 @@ struct MustUse {
345384
MustUse::new();
346385
```
347386

387+
r[attributes.diagnostics.must_use.function]
348388
When used on a function, if the [expression] of an [expression statement] is a
349389
[call expression] to that function, then the `unused_must_use` lint is
350390
violated.
@@ -357,6 +397,7 @@ fn five() -> i32 { 5i32 }
357397
five();
358398
```
359399

400+
r[attributes.diagnostics.must_use.traits]
360401
When used on a [trait declaration], a [call expression] of an [expression
361402
statement] to a function that returns an [impl trait] or a [dyn trait] of that trait violates
362403
the `unused_must_use` lint.
@@ -374,6 +415,7 @@ fn get_critical() -> impl Critical {
374415
get_critical();
375416
```
376417

418+
r[attributes.diagnostics.must_use.trait-function]
377419
When used on a function in a trait declaration, then the behavior also applies
378420
when the call expression is a function from an implementation of the trait.
379421

@@ -391,6 +433,7 @@ impl Trait for i32 {
391433
5i32.use_me();
392434
```
393435

436+
r[attributes.diagnostics.must_use.impl-function]
394437
When used on a function in a trait implementation, the attribute does nothing.
395438

396439
> Note: Trivial no-op expressions containing the value will not violate the
@@ -425,36 +468,59 @@ When used on a function in a trait implementation, the attribute does nothing.
425468
426469
## The `diagnostic` tool attribute namespace
427470
471+
r[attributes.diagnostics.namespace]
472+
473+
r[attributes.diagnostics.namespace.general]
428474
The `#[diagnostic]` attribute namespace is a home for attributes to influence compile-time error messages.
429475
The hints provided by these attributes are not guaranteed to be used.
476+
477+
r[attributes.diagnostics.namespace.unknown-invalid-syntax]
430478
Unknown attributes in this namespace are accepted, though they may emit warnings for unused attributes.
431479
Additionally, invalid inputs to known attributes will typically be a warning (see the attribute definitions for details).
432480
This is meant to allow adding or discarding attributes and changing inputs in the future to allow changes without the need to keep the non-meaningful attributes or options working.
433481
434482
### The `diagnostic::on_unimplemented` attribute
435483
484+
r[attributes.diagnostics.on_unimplemented]
485+
486+
r[attributes.diagnostics.on_unimplemented.general]
436487
The `#[diagnostic::on_unimplemented]` attribute is a hint to the compiler to supplement the error message that would normally be generated in scenarios where a trait is required but not implemented on a type.
488+
489+
r[attributes.diagnostics.on_unimplemented.restriction]
437490
The attribute should be placed on a [trait declaration], though it is not an error to be located in other positions.
491+
492+
r[attributes.diagnostics.on_unimplemented.syntax]
438493
The attribute uses the [_MetaListNameValueStr_] syntax to specify its inputs, though any malformed input to the attribute is not considered as an error to provide both forwards and backwards compatibility.
439-
The following keys have the given meaning:
440494
495+
496+
r[attributes.diagnostics.on_unimplemented.keys]
497+
The following keys have the given meaning:
441498
* `message` --- The text for the top level error message.
442499
* `label` --- The text for the label shown inline in the broken code in the error message.
443500
* `note` --- Provides additional notes.
444501
502+
r[attributes.diagnostics.on_unimplemented-note-repetition]
445503
The `note` option can appear several times, which results in several note messages being emitted.
504+
505+
r[attributes.diagnostics.on_unimplemented.repetition]
446506
If any of the other options appears several times the first occurrence of the relevant option specifies the actually used value.
507+
508+
r[attributes.diagnostics.on_unimplemented.warnings]
447509
Any other occurrence generates an lint warning.
448510
For any other non-existing option a lint-warning is generated.
449511
512+
r[attributes.diagnostics.format-string]
450513
All three options accept a string as an argument, interpreted using the same formatting as a [`std::fmt`] string.
451-
Format parameters with the given named parameter will be replaced with the following text:
452514
515+
r[attributes.diagnostics.format-parameters]
516+
Format parameters with the given named parameter will be replaced with the following text:
453517
* `{Self}` --- The name of the type implementing the trait.
454518
* `{` *GenericParameterName* `}` --- The name of the generic argument's type for the given generic parameter.
455519
520+
r[attributes.diagnostics.invalid-formats]
456521
Any other format parameter will generate a warning, but will otherwise be included in the string as-is.
457522
523+
r[attributes.diagnostics.invalid-string]
458524
Invalid format strings may generate a warning, but are otherwise allowed, but may not display as intended.
459525
Format specifiers may generate a warning, but are otherwise ignored.
460526

0 commit comments

Comments
 (0)