File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change 1+ #![ warn( clippy:: result_map_unwrap_or) ]
2+
3+ fn main ( ) {
4+ let res: Result < usize , ( ) > = Ok ( 1 ) ;
5+
6+ // Check `RESULT_MAP_OR_NONE`.
7+ // Single line case.
8+ let _ = res. map ( |x| x + 1 ) . unwrap_or ( 0 ) ;
9+ // Multi-line case.
10+ #[ rustfmt:: skip]
11+ let _ = res. map ( |x| {
12+ x + 1
13+ } ) . unwrap_or ( 0 ) ;
14+ }
Original file line number Diff line number Diff line change 1+ error: called `map(f).unwrap_or(a)` on a Result value. This can be done more directly by calling `map_or(a, f)` instead
2+ --> $DIR/result_map_unwrap_or.rs:8:13
3+ |
4+ LL | let _ = res.map(|x| x + 1).unwrap_or(0);
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+ |
7+ = note: `-D clippy::result-map-unwrap-or` implied by `-D warnings`
8+ = note: replace `map(|x| x + 1).unwrap_or(0)` with `map_or(0, |x| x + 1)`
9+
10+ error: called `map(f).unwrap_or(a)` on a Result value. This can be done more directly by calling `map_or(a, f)` instead
11+ --> $DIR/result_map_unwrap_or.rs:11:13
12+ |
13+ LL | let _ = res.map(|x| {
14+ | _____________^
15+ LL | | x + 1
16+ LL | | }).unwrap_or(0);
17+ | |______________________________________^
18+
19+ error: aborting due to 2 previous errors
20+
You can’t perform that action at this time.
0 commit comments