]> git.lizzy.rs Git - rust.git/blob - tests/ui/shadow.rs
Auto merge of #8374 - Alexendoo:bless-revisions, r=camsteffen
[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     let y = 1;
21     let y = match y {
22         1 => 2,
23         _ => 3,
24     };
25     None
26 }
27
28 fn shadow_unrelated() {
29     let x = 1;
30     let x = 2;
31 }
32
33 fn syntax() {
34     fn f(x: u32) {
35         let x = 1;
36     }
37     let x = 1;
38     match Some(1) {
39         Some(1) => {},
40         Some(x) => {
41             let x = 1;
42         },
43         _ => {},
44     }
45     if let Some(x) = Some(1) {}
46     while let Some(x) = Some(1) {}
47     let _ = |[x]: [u32; 1]| {
48         let x = 1;
49     };
50     let y = Some(1);
51     if let Some(y) = y {}
52 }
53
54 fn negative() {
55     match Some(1) {
56         Some(x) if x == 1 => {},
57         Some(x) => {},
58         None => {},
59     }
60     match [None, Some(1)] {
61         [Some(x), None] | [None, Some(x)] => {},
62         _ => {},
63     }
64     if let Some(x) = Some(1) {
65         let y = 1;
66     } else {
67         let x = 1;
68         let y = 1;
69     }
70     let x = 1;
71     #[allow(clippy::shadow_unrelated)]
72     let x = 1;
73 }
74
75 fn foo<T>(_: T) {}
76
77 fn question_mark() -> Option<()> {
78     let val = 1;
79     // `?` expands with a `val` binding
80     None?;
81     None
82 }
83
84 pub async fn foo1(_a: i32) {}
85
86 pub async fn foo2(_a: i32, _b: i64) {
87     let _b = _a;
88 }
89
90 fn main() {}