Skip to content

Commit 3d1f83e

Browse files
committed
map_identity Add tests for needless .map_err
1 parent 35b1453 commit 3d1f83e

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

tests/ui/map_identity.fixed

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ fn main() {
1616
let _: Result<i8, f32> = Err(2.3).map(|x: i8| {
1717
return x + 3;
1818
});
19+
let _: Result<u32, u32> = Ok(1);
20+
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
1921
}
2022

2123
fn not_identity(x: &u16) -> u16 {

tests/ui/map_identity.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ fn main() {
1818
let _: Result<i8, f32> = Err(2.3).map(|x: i8| {
1919
return x + 3;
2020
});
21+
let _: Result<u32, u32> = Ok(1).map_err(|a| a);
22+
let _: Result<u32, u32> = Ok(1).map_err(|a: u32| a * 42);
2123
}
2224

2325
fn not_identity(x: &u16) -> u16 {

tests/ui/map_identity.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,11 @@ LL | | return x;
3333
LL | | });
3434
| |______^ help: remove the call to `map`
3535

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

0 commit comments

Comments
 (0)