Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4f71ff3

Browse files
committed
add test case for option_map_or_none
1 parent 2ed4a8a commit 4f71ff3

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

tests/ui/option_map_or_none.fixed

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
fn main() {
66
let opt = Some(1);
7+
let bar = |_| {
8+
Some(1)
9+
};
710

811
// Check `OPTION_MAP_OR_NONE`.
912
// Single line case.
10-
let _ = opt.map(|x| Some(x + 1));
13+
let _ :Option<i32> = opt.map(|x| x + 1);
1114
// Multi-line case.
1215
#[rustfmt::skip]
13-
let _ = opt.map(|x| {
14-
Some(x + 1)
16+
let _ :Option<i32> = opt.map(|x| {
17+
x + 1
1518
});
19+
// function returning `Option`
20+
let _ :Option<i32> = opt.and_then(bar);
1621
}

tests/ui/option_map_or_none.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@
44

55
fn main() {
66
let opt = Some(1);
7+
let bar = |_| {
8+
Some(1)
9+
};
710

811
// Check `OPTION_MAP_OR_NONE`.
912
// Single line case.
10-
let _ = opt.map_or(None, |x| Some(x + 1));
13+
let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
1114
// Multi-line case.
1215
#[rustfmt::skip]
13-
let _ = opt.map_or(None, |x| {
16+
let _ :Option<i32> = opt.map_or(None, |x| {
1417
Some(x + 1)
1518
});
19+
// function returning `Option`
20+
let _ :Option<i32> = opt.map_or(None, bar);
1621
}

tests/ui/option_map_or_none.stderr

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
22
--> $DIR/option_map_or_none.rs:10:13
33
|
4-
LL | let _ = opt.map_or(None, |x| Some(x + 1));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| Some(x + 1))`
4+
LL | let _ :Option<i32> = opt.map_or(None, |x| Some(x + 1));
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| x + 1)`
66
|
77
= note: `-D clippy::option-map-or-none` implied by `-D warnings`
88

99
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
1010
--> $DIR/option_map_or_none.rs:13:13
1111
|
12-
LL | let _ = opt.map_or(None, |x| {
12+
LL | let _ :Option<i32> = opt.map_or(None, |x| {
1313
| _____________^
1414
LL | | Some(x + 1)
1515
LL | | });
1616
| |_________________________^
1717
|
1818
help: try using `map` instead
1919
|
20-
LL ~ let _ = opt.map(|x| {
21-
LL + Some(x + 1)
20+
LL ~ let _ :Option<i32> = opt.map(|x| {
21+
LL + x + 1
2222
LL ~ });
2323
|
2424

25-
error: aborting due to 2 previous errors
25+
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `map(..)` instead
26+
--> $DIR/option_map_or_none.rs:20:26
27+
|
28+
LL | let _ :Option<i32> = opt.map_or(None, bar);
29+
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
30+
31+
error: aborting due to 3 previous errors
2632

0 commit comments

Comments
 (0)