Skip to content

Commit

Permalink
Add new test for result_map_or_into_option extension
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 23, 2023
1 parent 2817c5f commit 5d330d0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
7 changes: 7 additions & 0 deletions tests/ui/result_map_or_into_option.fixed
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
fn main() {
let opt: Result<u32, &str> = Ok(1);
let _ = opt.ok();
//~^ ERROR: called `map_or(None, Some)` on a `Result` value.
let _ = opt.ok();
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
#[rustfmt::skip]
let _ = opt.ok();
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value

let rewrap = |s: u32| -> Option<u32> { Some(s) };

Expand All @@ -14,4 +20,5 @@ fn main() {
// return should not emit the lint
let opt: Result<u32, &str> = Ok(1);
_ = opt.map_or(None, |_x| Some(1));
let _ = opt.map_or_else(|a| a.parse::<u32>().ok(), Some);
}
7 changes: 7 additions & 0 deletions tests/ui/result_map_or_into_option.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
fn main() {
let opt: Result<u32, &str> = Ok(1);
let _ = opt.map_or(None, Some);
//~^ ERROR: called `map_or(None, Some)` on a `Result` value.
let _ = opt.map_or_else(|_| None, Some);
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
#[rustfmt::skip]
let _ = opt.map_or_else(|_| { None }, Some);
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value

let rewrap = |s: u32| -> Option<u32> { Some(s) };

Expand All @@ -14,4 +20,5 @@ fn main() {
// return should not emit the lint
let opt: Result<u32, &str> = Ok(1);
_ = opt.map_or(None, |_x| Some(1));
let _ = opt.map_or_else(|a| a.parse::<u32>().ok(), Some);
}
14 changes: 13 additions & 1 deletion tests/ui/result_map_or_into_option.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,17 @@ LL | let _ = opt.map_or(None, Some);
= note: `-D clippy::result-map-or-into-option` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]`

error: aborting due to previous error
error: called `map_or_else(|_| None, Some)` on a `Result` value
--> $DIR/result_map_or_into_option.rs:7:13
|
LL | let _ = opt.map_or_else(|_| None, Some);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()`

error: called `map_or_else(|_| None, Some)` on a `Result` value
--> $DIR/result_map_or_into_option.rs:10:13
|
LL | let _ = opt.map_or_else(|_| { None }, Some);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()`

error: aborting due to 3 previous errors

0 comments on commit 5d330d0

Please sign in to comment.