summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/suspicious_map.rs
blob: 3a2a10cf09ea51082cacd662a474d28ef8cdd252 (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
32
#![warn(clippy::suspicious_map)]

fn main() {
    let _ = (0..3).map(|x| x + 2).count();

    let f = |x| x + 1;
    let _ = (0..3).map(f).count();
}

fn negative() {
    // closure with side effects
    let mut sum = 0;
    let _ = (0..3).map(|x| sum += x).count();

    // closure variable with side effects
    let ext_closure = |x| sum += x;
    let _ = (0..3).map(ext_closure).count();

    // closure that returns unit
    let _ = (0..3)
        .map(|x| {
            // do nothing
        })
        .count();

    // external function
    let _ = (0..3).map(do_something).count();
}

fn do_something<T>(t: T) -> String {
    unimplemented!()
}