mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 07:04:18 +00:00
Add new test for result_map_or_into_option
extension
This commit is contained in:
parent
2817c5fc14
commit
5d330d08fb
3 changed files with 27 additions and 1 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue