fix suggestion message

This commit is contained in:
togami2864 2021-11-18 00:43:49 +09:00
parent 006c442657
commit 8e317f5283
3 changed files with 27 additions and 2 deletions

View File

@ -14,4 +14,9 @@ fn main() {
let _: Option<i32> = opt.map(|x| x + 1);
// function returning `Option`
let _: Option<i32> = opt.and_then(bar);
let _: Option<i32> = opt.and_then(|x| {
let offset = 0;
let height = x;
Some(offset + height)
});
}

View File

@ -18,7 +18,7 @@ fn main() {
let _: Option<i32> = opt.map_or(None, bar);
let _: Option<i32> = opt.map_or(None, |x| {
let offset = 0;
let height = 1;
let height = x;
Some(offset + height)
});
}

View File

@ -21,5 +21,25 @@ error: called `map_or(None, ..)` on an `Option` value. This can be done more dir
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
error: called `map_or(None, ..)` on an `Option` value. This can be done more directly by calling `and_then(..)` instead
--> $DIR/option_map_or_none.rs:19:26
|
LL | let _: Option<i32> = opt.map_or(None, |x| {
| __________________________^
LL | | let offset = 0;
LL | | let height = x;
LL | | Some(offset + height)
LL | | });
| |______^
|
help: try using `and_then` instead
|
LL ~ let _: Option<i32> = opt.and_then(|x| {
LL + let offset = 0;
LL + let height = x;
LL + Some(offset + height)
LL ~ });
|
error: aborting due to 4 previous errors