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 952f295 commit a980fff
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/ui/manual_ok_or.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ error: this pattern reimplements `Option::ok_or`
LL | foo.map_or(Err("error"), Ok);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace with: `foo.ok_or("error")`

error: called `map_or(Err(_), Ok)` on an `Option` value
--> $DIR/manual_ok_or.rs:14:5
|
LL | foo.map_or(Err("error"), Ok);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `ok_or` instead: `foo.ok_or("error")`
|
= 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: this pattern reimplements `Option::ok_or`
--> $DIR/manual_ok_or.rs:17:5
|
Expand All @@ -38,5 +47,5 @@ LL + "{}{}{}{}{}{}{}",
LL ~ "Alice", "Bob", "Sarah", "Marc", "Sandra", "Eric", "Jenifer"));
|

error: aborting due to 4 previous errors
error: aborting due to 5 previous errors

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 _ = 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 _ = 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:13
|
LL | let _ = 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 a980fff

Please sign in to comment.