]> git.lizzy.rs Git - rust.git/blob - tests/ui/shadow.rs
Rewrite shadow lint
[rust.git] / tests / ui / shadow.rs
1 #![warn(clippy::shadow_same, clippy::shadow_reuse, clippy::shadow_unrelated)]
2
3 fn shadow_same() {
4     let x = 1;
5     let x = x;
6     let mut x = &x;
7     let x = &mut x;
8     let x = *x;
9 }
10
11 fn shadow_reuse() -> Option<()> {
12     let x = ([[0]], ());
13     let x = x.0;
14     let x = x[0];
15     let [x] = x;
16     let x = Some(x);
17     let x = foo(x);
18     let x = || x;
19     let x = Some(1).map(|_| x)?;
20     None
21 }
22
23 fn shadow_unrelated() {
24     let x = 1;
25     let x = 2;
26 }
27
28 fn syntax() {
29     fn f(x: u32) {
30         let x = 1;
31     }
32     let x = 1;
33     match Some(1) {
34         Some(1) => {},
35         Some(x) => {
36             let x = 1;
37         },
38         _ => {},
39     }
40     if let Some(x) = Some(1) {}
41     while let Some(x) = Some(1) {}
42     let _ = |[x]: [u32; 1]| {
43         let x = 1;
44     };
45 }
46
47 fn negative() {
48     match Some(1) {
49         Some(x) if x == 1 => {},
50         Some(x) => {},
51         None => {},
52     }
53     match [None, Some(1)] {
54         [Some(x), None] | [None, Some(x)] => {},
55         _ => {},
56     }
57     if let Some(x) = Some(1) {
58         let y = 1;
59     } else {
60         let x = 1;
61         let y = 1;
62     }
63     let x = 1;
64     #[allow(clippy::shadow_unrelated)]
65     let x = 1;
66 }
67
68 fn foo<T>(_: T) {}
69
70 fn question_mark() -> Option<()> {
71     let val = 1;
72     // `?` expands with a `val` binding
73     None?;
74     None
75 }
76
77 fn main() {}