about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/flat_map_identity.fixed
blob: 06a3eee9d84c9bbe9b88bdc05acb8b4678ef0907 (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
30
31
#![allow(unused_imports, clippy::needless_return)]
#![warn(clippy::flat_map_identity)]

use std::convert;

fn main() {
    let iterator = [[0, 1], [2, 3], [4, 5]].iter();
    let _ = iterator.flatten();
    //~^ flat_map_identity

    let iterator = [[0, 1], [2, 3], [4, 5]].iter();
    let _ = iterator.flatten();
    //~^ flat_map_identity

    let iterator = [[0, 1], [2, 3], [4, 5]].iter();
    let _ = iterator.flatten();
    //~^ flat_map_identity
}

fn issue15198() {
    let x = [[1, 2], [3, 4]];
    // don't lint: this is an `Iterator<Item = &[i32, i32]>`
    // match ergonomics makes the binding patterns into references
    // so that its type changes to `Iterator<Item = [&i32, &i32]>`
    let _ = x.iter().flat_map(|[x, y]| [x, y]);
    let _ = x.iter().flat_map(|x| [x[0]]);

    // no match ergonomics for `[i32, i32]`
    let _ = x.iter().copied().flatten();
    //~^ flat_map_identity
}