mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Auto merge of #7996 - togami2864:test-map-or-none, r=Manishearth
Add test case for RESULT_MAP_OR_INTO_OPTION just added test case for RESULT_MAP_OR_INTO_OPTION. changelog: none
This commit is contained in:
commit
0d283cc44c
3 changed files with 21 additions and 5 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
fn main() {
|
||||
let opt = Some(1);
|
||||
let r: Result<i32, i32> = Ok(1);
|
||||
let bar = |_| Some(1);
|
||||
|
||||
// Check `OPTION_MAP_OR_NONE`.
|
||||
|
@ -19,4 +20,7 @@ fn main() {
|
|||
let height = x;
|
||||
Some(offset + height)
|
||||
});
|
||||
|
||||
// Check `RESULT_MAP_OR_INTO_OPTION`.
|
||||
let _: Option<i32> = r.ok();
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
|
||||
fn main() {
|
||||
let opt = Some(1);
|
||||
let r: Result<i32, i32> = Ok(1);
|
||||
let bar = |_| Some(1);
|
||||
|
||||
// Check `OPTION_MAP_OR_NONE`.
|
||||
|
@ -21,4 +22,7 @@ fn main() {
|
|||
let height = x;
|
||||
Some(offset + height)
|
||||
});
|
||||
|
||||
// Check `RESULT_MAP_OR_INTO_OPTION`.
|
||||
let _: Option<i32> = r.map_or(None, Some);
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
|
||||
--> $DIR/option_map_or_none.rs:11:26
|
||||
--> $DIR/option_map_or_none.rs:12:26
|
||||
|
|
||||
LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)`
|
||||
|
@ -7,7 +7,7 @@ LL | let _: Option<i32> = opt.map_or(None, |x| Some(x + 1));
|
|||
= note: `-D clippy::option-map-or-none` implied by `-D warnings`
|
||||
|
||||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
|
||||
--> $DIR/option_map_or_none.rs:14:26
|
||||
--> $DIR/option_map_or_none.rs:15:26
|
||||
|
|
||||
LL | let _: Option<i32> = opt.map_or(None, |x| {
|
||||
| __________________________^
|
||||
|
@ -16,13 +16,13 @@ LL | | });
|
|||
| |_________________________^ help: try using `map` instead: `opt.map(|x| x + 1)`
|
||||
|
||||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
|
||||
--> $DIR/option_map_or_none.rs:18:26
|
||||
--> $DIR/option_map_or_none.rs:19:26
|
||||
|
|
||||
LL | let _: Option<i32> = opt.map_or(None, bar);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
|
||||
|
||||
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
|
||||
--> $DIR/option_map_or_none.rs:19:26
|
||||
--> $DIR/option_map_or_none.rs:20:26
|
||||
|
|
||||
LL | let _: Option<i32> = opt.map_or(None, |x| {
|
||||
| __________________________^
|
||||
|
@ -41,5 +41,13 @@ LL + Some(offset + height)
|
|||
LL ~ });
|
||||
|
|
||||
|
||||
error: aborting due to 4 previous errors
|
||||
error: called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling `ok()` instead
|
||||
--> $DIR/option_map_or_none.rs:27:26
|
||||
|
|
||||
LL | let _: Option<i32> = r.map_or(None, Some);
|
||||
| ^^^^^^^^^^^^^^^^^^^^ help: try using `ok` instead: `r.ok()`
|
||||
|
|
||||
= note: `-D clippy::result-map-or-into-option` implied by `-D warnings`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
Loading…
Reference in a new issue