add test case for option_map_or_none
This commit is contained in:
parent
2ed4a8a3e6
commit
4f71ff3f84
@ -4,13 +4,18 @@
|
||||
|
||||
fn main() {
|
||||
let opt = Some(1);
|
||||
let bar = |_| {
|
||||
Some(1)
|
||||
};
|
||||
|
||||
// Check `OPTION_MAP_OR_NONE`.
|
||||
// Single line case.
|
||||
let _ = opt.map(|x| Some(x + 1));
|
||||
let _ :Option<i32> = opt.map(|x| x + 1);
|
||||
// Multi-line case.
|
||||
#[rustfmt::skip]
|
||||
let _ = opt.map(|x| {
|
||||
Some(x + 1)
|
||||
let _ :Option<i32> = opt.map(|x| {
|
||||
x + 1
|
||||
});
|
||||
// function returning `Option`
|
||||
let _ :Option<i32> = opt.and_then(bar);
|
||||
}
|
||||
|
@ -4,13 +4,18 @@
|
||||
|
||||
fn main() {
|
||||
let opt = Some(1);
|
||||
let bar = |_| {
|
||||
Some(1)
|
||||
};
|
||||
|
||||
// Check `OPTION_MAP_OR_NONE`.
|
||||
// Single line case.
|
||||
let _ = opt.map_or(None, |x| Some(x + 1));
|
||||
let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
|
||||
// Multi-line case.
|
||||
#[rustfmt::skip]
|
||||
let _ = opt.map_or(None, |x| {
|
||||
let _ :Option<i32> = opt.map_or(None, |x| {
|
||||
Some(x + 1)
|
||||
});
|
||||
// function returning `Option`
|
||||
let _ :Option<i32> = opt.map_or(None, bar);
|
||||
}
|
||||
|
@ -1,15 +1,15 @@
|
||||
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:10:13
|
||||
|
|
||||
LL | let _ = opt.map_or(None, |x| Some(x + 1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| Some(x + 1))`
|
||||
LL | let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| 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:13:13
|
||||
|
|
||||
LL | let _ = opt.map_or(None, |x| {
|
||||
LL | let _ :Option<i32> = opt.map_or(None, |x| {
|
||||
| _____________^
|
||||
LL | | Some(x + 1)
|
||||
LL | | });
|
||||
@ -17,10 +17,16 @@ LL | | });
|
||||
|
|
||||
help: try using `map` instead
|
||||
|
|
||||
LL ~ let _ = opt.map(|x| {
|
||||
LL + Some(x + 1)
|
||||
LL ~ let _ :Option<i32> = opt.map(|x| {
|
||||
LL + x + 1
|
||||
LL ~ });
|
||||
|
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
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:20:26
|
||||
|
|
||||
LL | let _ :Option<i32> = opt.map_or(None, bar);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user