]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/option_map_unit_fn.txt
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / src / docs / option_map_unit_fn.txt
1 ### What it does
2 Checks for usage of `option.map(f)` where f is a function
3 or closure that returns the unit type `()`.
4
5 ### Why is this bad?
6 Readability, this can be written more clearly with
7 an if let statement
8
9 ### Example
10 ```
11 let x: Option<String> = do_stuff();
12 x.map(log_err_msg);
13 x.map(|msg| log_err_msg(format_msg(msg)));
14 ```
15
16 The correct use would be:
17
18 ```
19 let x: Option<String> = do_stuff();
20 if let Some(msg) = x {
21     log_err_msg(msg);
22 }
23
24 if let Some(msg) = x {
25     log_err_msg(format_msg(msg));
26 }
27 ```