Skip to content

Commit a60fd9a

Browse files
Add new test for result_map_or_into_option extension
1 parent d1f1252 commit a60fd9a

File tree

3 files changed

+34
-5
lines changed

3 files changed

+34
-5
lines changed

tests/ui/result_map_or_into_option.fixed

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
#![warn(clippy::result_map_or_into_option)]
1+
#![deny(clippy::result_map_or_into_option)]
22

33
fn main() {
44
let opt: Result<u32, &str> = Ok(1);
55
let _ = opt.ok();
6+
//~^ ERROR: called `map_or(None, Some)` on a `Result` value.
7+
let _ = opt.ok();
8+
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
9+
#[rustfmt::skip]
10+
let _ = opt.ok();
11+
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
612

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

@@ -14,4 +20,5 @@ fn main() {
1420
// return should not emit the lint
1521
let opt: Result<u32, &str> = Ok(1);
1622
_ = opt.map_or(None, |_x| Some(1));
23+
let _ = opt.map_or_else(|a| a.parse::<u32>().ok(), Some);
1724
}

tests/ui/result_map_or_into_option.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
#![warn(clippy::result_map_or_into_option)]
1+
#![deny(clippy::result_map_or_into_option)]
22

33
fn main() {
44
let opt: Result<u32, &str> = Ok(1);
55
let _ = opt.map_or(None, Some);
6+
//~^ ERROR: called `map_or(None, Some)` on a `Result` value.
7+
let _ = opt.map_or_else(|_| None, Some);
8+
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
9+
#[rustfmt::skip]
10+
let _ = opt.map_or_else(|_| { None }, Some);
11+
//~^ ERROR: called `map_or_else(|_| None, Some)` on a `Result` value
612

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

@@ -14,4 +20,5 @@ fn main() {
1420
// return should not emit the lint
1521
let opt: Result<u32, &str> = Ok(1);
1622
_ = opt.map_or(None, |_x| Some(1));
23+
let _ = opt.map_or_else(|a| a.parse::<u32>().ok(), Some);
1724
}

tests/ui/result_map_or_into_option.stderr

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,23 @@ error: called `map_or(None, Some)` on a `Result` value. This can be done more di
44
LL | let _ = opt.map_or(None, Some);
55
| ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()`
66
|
7-
= note: `-D clippy::result-map-or-into-option` implied by `-D warnings`
8-
= help: to override `-D warnings` add `#[allow(clippy::result_map_or_into_option)]`
7+
note: the lint level is defined here
8+
--> $DIR/result_map_or_into_option.rs:1:9
9+
|
10+
LL | #![deny(clippy::result_map_or_into_option)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: called `map_or_else(|_| None, Some)` on a `Result` value
14+
--> $DIR/result_map_or_into_option.rs:7:13
15+
|
16+
LL | let _ = opt.map_or_else(|_| None, Some);
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()`
18+
19+
error: called `map_or_else(|_| None, Some)` on a `Result` value
20+
--> $DIR/result_map_or_into_option.rs:10:13
21+
|
22+
LL | let _ = opt.map_or_else(|_| { None }, Some);
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()`
924

10-
error: aborting due to previous error
25+
error: aborting due to 3 previous errors
1126

0 commit comments

Comments
 (0)