Skip to content

Commit f4815ed

Browse files
Add new test for result_map_or_into_option extension
1 parent 066f286 commit f4815ed

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

tests/ui/result_map_or_into_option.fixed

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
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
69

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

tests/ui/result_map_or_into_option.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
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
69

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

tests/ui/result_map_or_into_option.stderr

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,17 @@ 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()`
918

10-
error: aborting due to previous error
19+
error: aborting due to 2 previous errors
1120

0 commit comments

Comments
 (0)