Skip to content

Commit

Permalink
Update CHANGELOG
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 23, 2024
1 parent 8860550 commit 2f5a5f5
Show file tree
Hide file tree
Showing 4 changed files with 135 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5676,6 +5676,7 @@ Released 2018-09-13
[`unnecessary_mut_passed`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_mut_passed
[`unnecessary_operation`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_operation
[`unnecessary_owned_empty_strings`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_owned_empty_strings
[`unnecessary_result_map_or_else`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_result_map_or_else
[`unnecessary_safety_comment`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_comment
[`unnecessary_safety_doc`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_safety_doc
[`unnecessary_self_imports`]: https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_self_imports
Expand Down
47 changes: 46 additions & 1 deletion tests/ui/unnecessary_result_map_or_else.fixed
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
});
}
64 changes: 63 additions & 1 deletion tests/ui/unnecessary_result_map_or_else.rs
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
},
);
}
26 changes: 25 additions & 1 deletion tests/ui/unnecessary_result_map_or_else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,29 @@ LL | x.map_or_else(|err| err, |n| n);
= note: `-D clippy::unnecessary-result-map-or-else` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::unnecessary_result_map_or_else)]`

error: aborting due to 1 previous error
error: unused "map closure" when calling `Result::map_or_else` value
--> $DIR/unnecessary_result_map_or_else.rs:10:5
|
LL | x.map_or_else(|err: ()| err, |n: ()| n);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err: ()| err)`

error: unused "map closure" when calling `Result::map_or_else` value
--> $DIR/unnecessary_result_map_or_else.rs:15:19
|
LL | let y: &str = x.map_or_else(|err| err, |n| n);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)`

error: unused "map closure" when calling `Result::map_or_else` value
--> $DIR/unnecessary_result_map_or_else.rs:19:5
|
LL | / x.map_or_else(
LL | |
LL | | |err| err,
LL | | |n| {
... |
LL | | },
LL | | );
| |_____^ help: consider using `unwrap_or_else`: `x.unwrap_or_else(|err| err)`

error: aborting due to 4 previous errors

0 comments on commit 2f5a5f5

Please sign in to comment.