Skip to content

Commit 8ace46d

Browse files
committed
Update docs for map_flatten on Option
1 parent ea4db3a commit 8ace46d

File tree

1 file changed

+4
-1
lines changed
  • clippy_lints/src/methods

1 file changed

+4
-1
lines changed

clippy_lints/src/methods/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,17 +566,20 @@ declare_clippy_lint! {
566566
///
567567
/// ### Why is this bad?
568568
/// Readability, this can be written more concisely as
569-
/// `_.flat_map(_)`
569+
/// `_.flat_map(_)` for `Iterator` or `_.and_then(_)` for `Option`
570570
///
571571
/// ### Example
572572
/// ```rust
573573
/// let vec = vec![vec![1]];
574+
/// let opt = Some(5);
574575
///
575576
/// // Bad
576577
/// vec.iter().map(|x| x.iter()).flatten();
578+
/// opt.map(|x| Some(x*2)).flatten();
577579
///
578580
/// // Good
579581
/// vec.iter().flat_map(|x| x.iter());
582+
/// opt.and_then(|x| Some(x*2));
580583
/// ```
581584
#[clippy::version = "1.31.0"]
582585
pub MAP_FLATTEN,

0 commit comments

Comments
 (0)