Add test for option_map_or_err_ok lint

This commit is contained in:
Guillaume Gomez 2023-11-24 17:57:13 +01:00
parent ea733172e6
commit 3a3773fa30
4 changed files with 35 additions and 1 deletions

View File

@ -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
|
@ -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

View File

@ -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
}

View File

@ -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
}

View File

@ -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