summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/src/docs/or_fun_call.txt
blob: 6ce77cc268c51fcf20a56449031f51f80282a7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
### What it does
Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`,
`.or_insert(foo(..))` etc., and suggests to use `.or_else(|| foo(..))`,
`.unwrap_or_else(|| foo(..))`, `.unwrap_or_default()` or `.or_default()`
etc. instead.

### Why is this bad?
The function will always be called and potentially
allocate an object acting as the default.

### Known problems
If the function has side-effects, not calling it will
change the semantic of the program, but you shouldn't rely on that anyway.

### Example
```
foo.unwrap_or(String::new());
```

Use instead:
```
foo.unwrap_or_else(String::new);

// or

foo.unwrap_or_default();
```