-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8860550
commit 2f5a5f5
Showing
4 changed files
with
135 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,52 @@ | ||
#![warn(clippy::unnecessary_result_map_or_else)] | ||
#![allow(clippy::unnecessary_literal_unwrap)] | ||
#![allow(clippy::unnecessary_literal_unwrap, clippy::let_and_return, clippy::let_unit_value)] | ||
|
||
fn main() { | ||
let x: Result<(), ()> = Ok(()); | ||
x.unwrap_or_else(|err| err); //~ ERROR: unused "map closure" when calling | ||
|
||
// Type ascribtion. | ||
let x: Result<(), ()> = Ok(()); | ||
x.unwrap_or_else(|err: ()| err); //~ ERROR: unused "map closure" when calling | ||
|
||
// Auto-deref. | ||
let y = String::new(); | ||
let x: Result<&String, &String> = Ok(&y); | ||
let y: &str = x.unwrap_or_else(|err| err); //~ ERROR: unused "map closure" when calling | ||
|
||
// Temporary variable. | ||
let x: Result<(), ()> = Ok(()); | ||
x.unwrap_or_else(|err| err); | ||
|
||
// Should not warn. | ||
let x: Result<usize, usize> = Ok(0); | ||
x.map_or_else(|err| err, |n| n + 1); | ||
|
||
// Should not warn. | ||
let y = (); | ||
let x: Result<(), ()> = Ok(()); | ||
x.map_or_else(|err| err, |_| y); | ||
|
||
// Should not warn. | ||
let y = (); | ||
let x: Result<(), ()> = Ok(()); | ||
x.map_or_else(|err| err, |_| { | ||
let tmp = y; | ||
tmp | ||
}); | ||
|
||
// Should not warn. | ||
let x: Result<usize, usize> = Ok(1); | ||
x.map_or_else(|err| err, |n| { | ||
let tmp = n + 1; | ||
tmp | ||
}); | ||
|
||
// Should not warn. | ||
let y = 0; | ||
let x: Result<usize, usize> = Ok(1); | ||
x.map_or_else(|err| err, |n| { | ||
let tmp = n; | ||
y | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,69 @@ | ||
#![warn(clippy::unnecessary_result_map_or_else)] | ||
#![allow(clippy::unnecessary_literal_unwrap)] | ||
#![allow(clippy::unnecessary_literal_unwrap, clippy::let_and_return, clippy::let_unit_value)] | ||
|
||
fn main() { | ||
let x: Result<(), ()> = Ok(()); | ||
x.map_or_else(|err| err, |n| n); //~ ERROR: unused "map closure" when calling | ||
|
||
// Type ascribtion. | ||
let x: Result<(), ()> = Ok(()); | ||
x.map_or_else(|err: ()| err, |n: ()| n); //~ ERROR: unused "map closure" when calling | ||
|
||
// Auto-deref. | ||
let y = String::new(); | ||
let x: Result<&String, &String> = Ok(&y); | ||
let y: &str = x.map_or_else(|err| err, |n| n); //~ ERROR: unused "map closure" when calling | ||
|
||
// Temporary variable. | ||
let x: Result<(), ()> = Ok(()); | ||
x.map_or_else( | ||
//~^ ERROR: unused "map closure" when calling | ||
|err| err, | ||
|n| { | ||
let tmp = n; | ||
let tmp2 = tmp; | ||
tmp2 | ||
}, | ||
); | ||
|
||
// Should not warn. | ||
let x: Result<usize, usize> = Ok(0); | ||
x.map_or_else(|err| err, |n| n + 1); | ||
|
||
// Should not warn. | ||
let y = (); | ||
let x: Result<(), ()> = Ok(()); | ||
x.map_or_else(|err| err, |_| y); | ||
|
||
// Should not warn. | ||
let y = (); | ||
let x: Result<(), ()> = Ok(()); | ||
x.map_or_else( | ||
|err| err, | ||
|_| { | ||
let tmp = y; | ||
tmp | ||
}, | ||
); | ||
|
||
// Should not warn. | ||
let x: Result<usize, usize> = Ok(1); | ||
x.map_or_else( | ||
|err| err, | ||
|n| { | ||
let tmp = n + 1; | ||
tmp | ||
}, | ||
); | ||
|
||
// Should not warn. | ||
let y = 0; | ||
let x: Result<usize, usize> = Ok(1); | ||
x.map_or_else( | ||
|err| err, | ||
|n| { | ||
let tmp = n; | ||
y | ||
}, | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters