Skip to content

Commit e5beed3

Browse files
authored
Merge pull request #16 from rust-lang/fix/must-use
Fix build failure from must_use docs
2 parents f1c1c5d + feb981f commit e5beed3

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/code-considerations/design/must-use.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,29 +4,29 @@ The `#[must_use]` attribute can be applied to types or functions when failing to
44

55
As an example, `Result` is `#[must_use]` because failing to consider it may indicate a caller didn't realise a method was fallible:
66

7-
```rust
7+
```rust,ignore
88
// Is `check_status` infallible? Or did we forget to look at its `Result`?
99
check_status();
1010
```
1111

1212
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:
1313

14-
```rust
14+
```rust,ignore
1515
// A caller might assume this method mutates `a`
1616
a.saturating_add(b);
1717
```
1818

1919
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:
2020

21-
```rust
21+
```rust,ignore
2222
// A caller might not realise this code won't do anything
2323
// unless they call `collect`, `count`, etc.
2424
v.iter().map(|x| println!("{}", x));
2525
```
2626

2727
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:
2828

29-
```rust
29+
```rust,ignore
3030
thread::spawn(|| {
3131
// this background work isn't waited on
3232
});

0 commit comments

Comments
 (0)