Add test for option_map_or_err_ok
lint
This commit is contained in:
parent
ea733172e6
commit
3a3773fa30
@ -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
|
||||
|
||||
|
7
tests/ui/option_map_or_err_ok.fixed
Normal file
7
tests/ui/option_map_or_err_ok.fixed
Normal 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
|
||||
}
|
7
tests/ui/option_map_or_err_ok.rs
Normal file
7
tests/ui/option_map_or_err_ok.rs
Normal 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
|
||||
}
|
11
tests/ui/option_map_or_err_ok.stderr
Normal file
11
tests/ui/option_map_or_err_ok.stderr
Normal 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user