]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/or_fun_call.txt
Rollup merge of #102470 - est31:stabilize_const_char_convert, r=joshtriplett
[rust.git] / src / tools / clippy / src / docs / or_fun_call.txt
1 ### What it does
2 Checks for calls to `.or(foo(..))`, `.unwrap_or(foo(..))`,
3 `.or_insert(foo(..))` etc., and suggests to use `.or_else(|| foo(..))`,
4 `.unwrap_or_else(|| foo(..))`, `.unwrap_or_default()` or `.or_default()`
5 etc. instead.
6
7 ### Why is this bad?
8 The function will always be called and potentially
9 allocate an object acting as the default.
10
11 ### Known problems
12 If the function has side-effects, not calling it will
13 change the semantic of the program, but you shouldn't rely on that anyway.
14
15 ### Example
16 ```
17 foo.unwrap_or(String::new());
18 ```
19
20 Use instead:
21 ```
22 foo.unwrap_or_else(String::new);
23
24 // or
25
26 foo.unwrap_or_default();
27 ```