Skip to content

Commit

Permalink
#[must_use] on trait fns and impl fns docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Havvy committed Apr 3, 2018
1 parent 76303fb commit 18a952c
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,27 @@ fn main() {
}
```

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.

```rust
trait Trait {
#[must_use]
fn use_me(&self) -> i32;
}

impl Trait for i32 {
fn use_me(&self) -> i32 { 0i32 }
}

fn main() {
// Violates the `unused_must_use` lint.
5i32.use_me();
}
```

When used on a function in an implementation, the attribute does nothing.

> Note: Trivial no-op expressions containing the value will not violate the
> lint. Examples include wrapping the value in a type that does not implement
> [`Drop`] and then not using that type and being the final expression of a
Expand Down

0 comments on commit 18a952c

Please sign in to comment.