Skip to content

Commit 05fea2f

Browse files
committed
Move examples into example blocks
1 parent 940f314 commit 05fea2f

File tree

1 file changed

+49
-45
lines changed

1 file changed

+49
-45
lines changed

src/attributes/diagnostics.md

Lines changed: 49 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -360,63 +360,67 @@ The `must_use` attribute may include a message by using the [MetaNameValueStr] s
360360
r[attributes.diagnostics.must_use.type]
361361
When used on user-defined composite types, if the [expression] of an [expression statement] has that type, then the `unused_must_use` lint is violated.
362362

363-
```rust
364-
#[must_use]
365-
struct MustUse {
366-
// some fields
367-
}
368-
369-
# impl MustUse {
370-
# fn new() -> MustUse { MustUse {} }
371-
# }
372-
#
373-
// Violates the `unused_must_use` lint.
374-
MustUse::new();
375-
```
363+
> [!EXAMPLE]
364+
> ```rust
365+
> #[must_use]
366+
> struct MustUse {
367+
> // some fields
368+
> }
369+
>
370+
> # impl MustUse {
371+
> # fn new() -> MustUse { MustUse {} }
372+
> # }
373+
> #
374+
> // Violates the `unused_must_use` lint.
375+
> MustUse::new();
376+
> ```
376377
377378
r[attributes.diagnostics.must_use.fn]
378379
When used on a function, if the [expression] of an [expression statement] is a [call expression] to that function, then the `unused_must_use` lint is violated.
379380
380-
```rust
381-
#[must_use]
382-
fn five() -> i32 { 5i32 }
383-
384-
// Violates the unused_must_use lint.
385-
five();
386-
```
381+
> [!EXAMPLE]
382+
> ```rust
383+
> #[must_use]
384+
> fn five() -> i32 { 5i32 }
385+
>
386+
> // Violates the unused_must_use lint.
387+
> five();
388+
> ```
387389
388390
r[attributes.diagnostics.must_use.trait]
389391
When used on a [trait declaration], a [call expression] of an [expression statement] to a function that returns an [impl trait] or a [dyn trait] of that trait violates the `unused_must_use` lint.
390392
391-
```rust
392-
#[must_use]
393-
trait Critical {}
394-
impl Critical for i32 {}
395-
396-
fn get_critical() -> impl Critical {
397-
4i32
398-
}
399-
400-
// Violates the `unused_must_use` lint.
401-
get_critical();
402-
```
393+
> [!EXAMPLE]
394+
> ```rust
395+
> #[must_use]
396+
> trait Critical {}
397+
> impl Critical for i32 {}
398+
>
399+
> fn get_critical() -> impl Critical {
400+
> 4i32
401+
> }
402+
>
403+
> // Violates the `unused_must_use` lint.
404+
> get_critical();
405+
> ```
403406
404407
r[attributes.diagnostics.must_use.trait-function]
405408
When used on a function in a trait declaration, then the behavior also applies when the call expression is a function from an implementation of the trait.
406409
407-
```rust
408-
trait Trait {
409-
#[must_use]
410-
fn use_me(&self) -> i32;
411-
}
412-
413-
impl Trait for i32 {
414-
fn use_me(&self) -> i32 { 0i32 }
415-
}
416-
417-
// Violates the `unused_must_use` lint.
418-
5i32.use_me();
419-
```
410+
> [!EXAMPLE]
411+
> ```rust
412+
> trait Trait {
413+
> #[must_use]
414+
> fn use_me(&self) -> i32;
415+
> }
416+
>
417+
> impl Trait for i32 {
418+
> fn use_me(&self) -> i32 { 0i32 }
419+
> }
420+
>
421+
> // Violates the `unused_must_use` lint.
422+
> 5i32.use_me();
423+
> ```
420424
421425
r[attributes.diagnostics.must_use.trait-impl-function]
422426
When used on a function in a trait implementation, the attribute does nothing.

0 commit comments

Comments
 (0)