Skip to content

Commit 2ed4a8a

Browse files
committed
fix suggestion in option_map_or_none
1 parent f51fb34 commit 2ed4a8a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

clippy_lints/src/methods/option_map_or_none.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,12 @@ pub(super) fn check<'tcx>(
5353
let self_snippet = snippet(cx, recv.span, "..");
5454
let func_snippet = snippet(cx, map_arg.span, "..");
5555
let msg = "called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling \
56-
`and_then(..)` instead";
56+
`map(..)` instead";
5757
(
5858
OPTION_MAP_OR_NONE,
5959
msg,
60-
"try using `and_then` instead",
61-
format!("{0}.and_then({1})", self_snippet, func_snippet),
60+
"try using `map` instead",
61+
format!("{0}.map({1})", self_snippet, func_snippet),
6262
)
6363
} else if f_arg_is_some {
6464
let msg = "called `map_or(None, Some)` on a `Result` value. This can be done more directly by calling \

tests/ui/option_map_or_none.fixed

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ fn main() {
77

88
// Check `OPTION_MAP_OR_NONE`.
99
// Single line case.
10-
let _ = opt.and_then(|x| Some(x + 1));
10+
let _ = opt.map(|x| Some(x + 1));
1111
// Multi-line case.
1212
#[rustfmt::skip]
13-
let _ = opt.and_then(|x| {
13+
let _ = opt.map(|x| {
1414
Some(x + 1)
1515
});
1616
}

tests/ui/option_map_or_none.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
1+
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
|
44
LL | let _ = opt.map_or(None, |x| Some(x + 1));
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(|x| Some(x + 1))`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try using `map` instead: `opt.map(|x| Some(x + 1))`
66
|
77
= note: `-D clippy::option-map-or-none` implied by `-D warnings`
88

9-
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
9+
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
|
1212
LL | let _ = opt.map_or(None, |x| {
@@ -15,9 +15,9 @@ LL | | Some(x + 1)
1515
LL | | });
1616
| |_________________________^
1717
|
18-
help: try using `and_then` instead
18+
help: try using `map` instead
1919
|
20-
LL ~ let _ = opt.and_then(|x| {
20+
LL ~ let _ = opt.map(|x| {
2121
LL + Some(x + 1)
2222
LL ~ });
2323
|

0 commit comments

Comments
 (0)