Skip to content

Commit

Permalink
add test case for option_map_or_none
Browse files Browse the repository at this point in the history
  • Loading branch information
togami2864 committed Nov 15, 2021
1 parent 2ed4a8a commit 4f71ff3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
11 changes: 8 additions & 3 deletions tests/ui/option_map_or_none.fixed
Expand Up @@ -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);
}
9 changes: 7 additions & 2 deletions tests/ui/option_map_or_none.rs
Expand Up @@ -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);
}
18 changes: 12 additions & 6 deletions tests/ui/option_map_or_none.stderr
@@ -1,26 +1,32 @@
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 | | });
| |_________________________^
|
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

0 comments on commit 4f71ff3

Please sign in to comment.