Skip to content

Commit

Permalink
Add test for option_map_or_err_ok lint
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Nov 24, 2023
1 parent b86903d commit 926ea0e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/ui/option_map_or_err_ok.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![warn(clippy::option_map_or_err_ok)]

fn main() {
let x = Some("a");
let _: Result<&str, &str> = x.ok_or("a");
//~^ ERROR: called `map_or(Err(_), Ok)` on an `Option` value
}
7 changes: 7 additions & 0 deletions tests/ui/option_map_or_err_ok.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#![warn(clippy::option_map_or_err_ok)]

fn main() {
let x = Some("a");
let _: Result<&str, &str> = x.map_or(Err("a"), Ok);
//~^ ERROR: called `map_or(Err(_), Ok)` on an `Option` value
}
11 changes: 11 additions & 0 deletions tests/ui/option_map_or_err_ok.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error: called `map_or(Err(_), Ok)` on an `Option` value
--> $DIR/option_map_or_err_ok.rs:5:33
|
LL | let _: Result<&str, &str> = x.map_or(Err("a"), Ok);
| ^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok_or` instead: `x.ok_or("a")`
|
= note: `-D clippy::option-map-or-err-ok` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::option_map_or_err_ok)]`

error: aborting due to previous error

0 comments on commit 926ea0e

Please sign in to comment.