Add new test for result_map_or_into_option extension

This commit is contained in:
Guillaume Gomez 2023-11-20 14:54:43 +01:00
parent 2817c5fc14
commit 5d330d08fb
3 changed files with 27 additions and 1 deletions

View file

@ -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) };
@ -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);
}

View file

@ -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) };
@ -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);
}

View file

@ -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