-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
A-documentationArea: Adding or improving documentationArea: Adding or improving documentationgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy
Description
Description
Clippy suggests replacing _.map(_).flatten(_) with .and_then(_) for an Option. For example, this code:
Some(10)
.map(|val| if val % 2 == 0 { Some(2) } else { None })
.flatten();
generates this clippy lint
warning: called `map(..).flatten()` on an `Option`
--> src/main.rs:2:13
|
2 | Some(10)
| _____________^
3 | | .map(|val| if val % 2 == 0 { Some(2) } else { None })
4 | | .flatten();
| |__________________^ help: try using `and_then` instead: `.and_then(|val| if val % 2 == 0 { Some(2) } else { None })`
|
= note: `#[warn(clippy::map_flatten)]` on by default
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#map_flatten
But the webpage linked in this lint suggests using _.flat_map(_) for Option types, yet .flat_map(_) does not exist on Option, instead the equivalent is .and_then(_). This isn't a huge deal, but it can be confusing when the clippy suggests one thing, and the link with further information suggests something else.
Version
rustc 1.60.0-nightly (777bb86bc 2022-01-20)
binary: rustc
commit-hash: 777bb86bcdbc568be7cff6eeeaaf81a89b4aa50b
commit-date: 2022-01-20
host: x86_64-apple-darwin
release: 1.60.0-nightly
LLVM version: 13.0.0
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
A-documentationArea: Adding or improving documentationArea: Adding or improving documentationgood first issueThese issues are a good way to get started with ClippyThese issues are a good way to get started with Clippy