Skip to content

Commit f376333

Browse files
committed
#[must_use] on trait fns and impl fns docs
1 parent 0ee01af commit f376333

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/attributes.md

+21
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,27 @@ fn main() {
414414
}
415415
```
416416

417+
When used on a function in a trait declaration, then the behavior also applies
418+
when the call expression is a function from an implementation of the trait.
419+
420+
```rust
421+
trait Trait {
422+
#[must_use]
423+
fn use_me(&self) -> i32;
424+
}
425+
426+
impl Trait for i32 {
427+
fn use_me(&self) -> i32 { 0i32 }
428+
}
429+
430+
fn main() {
431+
// Violates the `unused_must_use` lint.
432+
5i32.use_me();
433+
}
434+
```
435+
436+
When used on a function in an implementation, the attribute does nothing.
437+
417438
> Note: Trivial no-op expressions containing the value will not violate the
418439
> lint. Examples include wrapping the value in a type that does not implement
419440
> [`Drop`] and then not using that type and being the final expression of a

0 commit comments

Comments
 (0)