diff --git a/src/code-considerations/design/must-use.md b/src/code-considerations/design/must-use.md index 588c8c6..10220b6 100644 --- a/src/code-considerations/design/must-use.md +++ b/src/code-considerations/design/must-use.md @@ -4,21 +4,21 @@ The `#[must_use]` attribute can be applied to types or functions when failing to As an example, `Result` is `#[must_use]` because failing to consider it may indicate a caller didn't realise a method was fallible: -```rust +```rust,ignore // Is `check_status` infallible? Or did we forget to look at its `Result`? check_status(); ``` Operators like `saturating_add` are also `#[must_use]` because failing to consider their output might indicate a caller didn't realise they don't mutate the left-hand-side: -```rust +```rust,ignore // A caller might assume this method mutates `a` a.saturating_add(b); ``` Combinators produced by the `Iterator` trait are `#[must_use]` because failing to use them might indicate a caller didn't realize `Iterator`s are lazy and won't actually do anything unless you drive them: -```rust +```rust,ignore // A caller might not realise this code won't do anything // unless they call `collect`, `count`, etc. v.iter().map(|x| println!("{}", x)); @@ -26,7 +26,7 @@ v.iter().map(|x| println!("{}", x)); On the other hand, `thread::JoinHandle` isn't `#[must_use]` because spawning fire-and-forget work is a legitimate pattern and forcing callers to explicitly ignore handles could be a nuisance rather than an indication of a bug: -```rust +```rust,ignore thread::spawn(|| { // this background work isn't waited on });