Skip to content

Commit

Permalink
map_identity Add tests for needless .map_err
Browse files Browse the repository at this point in the history
  • Loading branch information
dswij committed Mar 1, 2022
1 parent 35b1453 commit 3d1f83e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions tests/ui/map_identity.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ fn main() {
let _: Result<i8, f32> = Err(2.3).map(|x: i8| {
return x + 3;
});
let _: Result<u32, u32> = Ok(1);
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
}

fn not_identity(x: &u16) -> u16 {
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/map_identity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ fn main() {
let _: Result<i8, f32> = Err(2.3).map(|x: i8| {
return x + 3;
});
let _: Result<u32, u32> = Ok(1).map_err(|a| a);
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
}

fn not_identity(x: &u16) -> u16 {
Expand Down
8 changes: 7 additions & 1 deletion tests/ui/map_identity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,11 @@ LL | | return x;
LL | | });
| |______^ help: remove the call to `map`

error: aborting due to 5 previous errors
error: unnecessary map of the identity function
--> $DIR/map_identity.rs:21:36
|
LL | let _: Result<u32, u32> = Ok(1).map_err(|a| a);
| ^^^^^^^^^^^^^^^ help: remove the call to `map_err`

error: aborting due to 6 previous errors

0 comments on commit 3d1f83e

Please sign in to comment.