Skip to content

Commit 89a82f7

Browse files
committed
Update diagnostic to use the attribute template
1 parent 05fea2f commit 89a82f7

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

src/attributes/diagnostics.md

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -349,10 +349,37 @@ r[attributes.diagnostics.must_use]
349349
## The `must_use` attribute
350350

351351
r[attributes.diagnostics.must_use.intro]
352-
The *`must_use` attribute* is used to issue a diagnostic warning when a value is not "used".
352+
The *`must_use` [attribute][attributes]* is used to issue a diagnostic warning when a value is not used.
353+
354+
r[attributes.diagnostics.must_use.syntax]
355+
The `must_use` attribute uses either the [MetaWord] syntax or the [MetaNameValueStr] syntax to be able to [specify a message][attributes.diagnostics.must_use.message].
356+
357+
> [!EXAMPLE]
358+
> ```rust
359+
> #[must_use]
360+
> fn use_me() -> u8 { 0 }
361+
>
362+
> #[must_use = "explanation of why it must be used"]
363+
> fn use_me2() -> u8 { 0 }
364+
> ```
353365
354366
r[attributes.diagnostics.must_use.allowed-positions]
355-
The `must_use` attribute can be applied to user-defined composite types ([`struct`s][struct], [`enum`s][enum], and [`union`s][union]), [functions], and [traits].
367+
The `must_use` attribute may be applied to a:
368+
369+
- [Struct]
370+
- [Enumeration]
371+
- [Union]
372+
- [Function]
373+
- [Trait]
374+
375+
> [!NOTE]
376+
> `rustc` currently warns in other positions, but this may be rejected in the future.
377+
378+
r[attributes.diagnostics.must_use.duplicates]
379+
The `must_use` attribute may only be specified once on an item.
380+
381+
> [!NOTE]
382+
> `rustc` currently warns on subsequent duplicate `must_use` attributes. This may become an error in the future.
356383
357384
r[attributes.diagnostics.must_use.message]
358385
The `must_use` attribute may include a message by using the [MetaNameValueStr] syntax such as `#[must_use = "example message"]`. The message will be given alongside the warning.
@@ -661,7 +688,7 @@ The first error message includes a somewhat confusing error message about the re
661688
[call expression]: ../expressions/call-expr.md
662689
[dyn trait]: ../types/trait-object.md
663690
[enum variant]: ../items/enumerations.md
664-
[enum]: ../items/enumerations.md
691+
[enumeration]: ../items/enumerations.md
665692
[expression statement]: ../statements.md#expression-statements
666693
[expression]: ../expressions.md
667694
[external block item]: ../items/external-blocks.md

0 commit comments

Comments
 (0)