]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/src/docs/result_map_unit_fn.txt
Auto merge of #102529 - colinba:master, r=joshtriplett
[rust.git] / src / tools / clippy / src / docs / result_map_unit_fn.txt
1 ### What it does
2 Checks for usage of `result.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: Result<String, 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: Result<String, String> = do_stuff();
20 if let Ok(msg) = x {
21     log_err_msg(msg);
22 };
23 if let Ok(msg) = x {
24     log_err_msg(format_msg(msg));
25 };
26 ```