about summary refs log tree commit diff
path: root/src/tools/clippy/tests/ui/shadow.rs
blob: 02e838456d0b574559f34404e79f22ffa158100e (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]

fn shadow_same() {
    let x = 1;
    let x = x;
    let mut x = &x;
    let x = &mut x;
    let x = *x;
}

fn shadow_reuse() -> Option<()> {
    let x = ([[0]], ());
    let x = x.0;
    let x = x[0];
    let [x] = x;
    let x = Some(x);
    let x = foo(x);
    let x = || x;
    let x = Some(1).map(|_| x)?;
    None
}

fn shadow_unrelated() {
    let x = 1;
    let x = 2;
}

fn syntax() {
    fn f(x: u32) {
        let x = 1;
    }
    let x = 1;
    match Some(1) {
        Some(1) => {},
        Some(x) => {
            let x = 1;
        },
        _ => {},
    }
    if let Some(x) = Some(1) {}
    while let Some(x) = Some(1) {}
    let _ = |[x]: [u32; 1]| {
        let x = 1;
    };
}

fn negative() {
    match Some(1) {
        Some(x) if x == 1 => {},
        Some(x) => {},
        None => {},
    }
    match [None, Some(1)] {
        [Some(x), None] | [None, Some(x)] => {},
        _ => {},
    }
    if let Some(x) = Some(1) {
        let y = 1;
    } else {
        let x = 1;
        let y = 1;
    }
    let x = 1;
    #[allow(clippy::shadow_unrelated)]
    let x = 1;
}

fn foo<T>(_: T) {}

fn question_mark() -> Option<()> {
    let val = 1;
    // `?` expands with a `val` binding
    None?;
    None
}

fn main() {}