Skip to content

Commit 8e317f5

Browse files
committed
fix suggestion message
1 parent 006c442 commit 8e317f5

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

tests/ui/option_map_or_none.fixed

+5
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,9 @@ fn main() {
1414
let _: Option<i32> = opt.map(|x| x + 1);
1515
// function returning `Option`
1616
let _: Option<i32> = opt.and_then(bar);
17+
let _: Option<i32> = opt.and_then(|x| {
18+
let offset = 0;
19+
let height = x;
20+
Some(offset + height)
21+
});
1722
}

tests/ui/option_map_or_none.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn main() {
1818
let _: Option<i32> = opt.map_or(None, bar);
1919
let _: Option<i32> = opt.map_or(None, |x| {
2020
let offset = 0;
21-
let height = 1;
21+
let height = x;
2222
Some(offset + height)
2323
});
2424
}

tests/ui/option_map_or_none.stderr

+21-1
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,25 @@ error: called `map_or(None, ..)` on an `Option` value. This can be done more dir
2121
LL | let _: Option<i32> = opt.map_or(None, bar);
2222
| ^^^^^^^^^^^^^^^^^^^^^ help: try using `and_then` instead: `opt.and_then(bar)`
2323

24-
error: aborting due to 3 previous errors
24+
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
25+
--> $DIR/option_map_or_none.rs:19:26
26+
|
27+
LL | let _: Option<i32> = opt.map_or(None, |x| {
28+
| __________________________^
29+
LL | | let offset = 0;
30+
LL | | let height = x;
31+
LL | | Some(offset + height)
32+
LL | | });
33+
| |______^
34+
|
35+
help: try using `and_then` instead
36+
|
37+
LL ~ let _: Option<i32> = opt.and_then(|x| {
38+
LL + let offset = 0;
39+
LL + let height = x;
40+
LL + Some(offset + height)
41+
LL ~ });
42+
|
43+
44+
error: aborting due to 4 previous errors
2545

0 commit comments

Comments
 (0)