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 20, 2023
1 parent cd26246 commit 3bc412a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 4 additions & 1 deletion tests/ui/result_map_or_into_option.fixed
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![warn(clippy::result_map_or_into_option)]
#![deny(clippy::result_map_or_into_option)]

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.

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

Expand Down
5 changes: 4 additions & 1 deletion tests/ui/result_map_or_into_option.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#![warn(clippy::result_map_or_into_option)]
#![deny(clippy::result_map_or_into_option)]

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.

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

Expand Down
15 changes: 12 additions & 3 deletions tests/ui/result_map_or_into_option.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,17 @@ error: called `map_or(None, Some)` on a `Result` value. This can be done more di
LL | let _ = opt.map_or(None, Some);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `opt.ok()`
|
= 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)]`
note: the lint level is defined here
--> $DIR/result_map_or_into_option.rs:1:9
|
LL | #![deny(clippy::result_map_or_into_option)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: called `map_or_else(|_| None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead
--> $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: aborting due to previous error
error: aborting due to 2 previous errors

0 comments on commit 3bc412a

Please sign in to comment.