summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/lines_filter_map_ok.rs
blob: 5aedc68633607193ff0a5cd28307151c2b75552b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//@run-rustfix

#![allow(unused, clippy::map_identity)]
#![warn(clippy::lines_filter_map_ok)]

use std::io::{self, BufRead, BufReader};

fn main() -> io::Result<()> {
    let f = std::fs::File::open("/")?;
    // Lint
    BufReader::new(f).lines().filter_map(Result::ok).for_each(|_| ());
    // Lint
    let f = std::fs::File::open("/")?;
    BufReader::new(f).lines().flat_map(Result::ok).for_each(|_| ());
    let s = "foo\nbar\nbaz\n";
    // Lint
    io::stdin().lines().filter_map(Result::ok).for_each(|_| ());
    // Lint
    io::stdin().lines().filter_map(|x| x.ok()).for_each(|_| ());
    // Do not lint (not a `Lines` iterator)
    io::stdin()
        .lines()
        .map(std::convert::identity)
        .filter_map(|x| x.ok())
        .for_each(|_| ());
    // Do not lint (not a `Result::ok()` extractor)
    io::stdin().lines().filter_map(|x| x.err()).for_each(|_| ());
    Ok(())
}