]> git.lizzy.rs Git - rust.git/blob - tests/ui/shadow.rs
Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
[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 }
51
52 fn negative() {
53     match Some(1) {
54         Some(x) if x == 1 => {},
55         Some(x) => {},
56         None => {},
57     }
58     match [None, Some(1)] {
59         [Some(x), None] | [None, Some(x)] => {},
60         _ => {},
61     }
62     if let Some(x) = Some(1) {
63         let y = 1;
64     } else {
65         let x = 1;
66         let y = 1;
67     }
68     let x = 1;
69     #[allow(clippy::shadow_unrelated)]
70     let x = 1;
71 }
72
73 fn foo<T>(_: T) {}
74
75 fn question_mark() -> Option<()> {
76     let val = 1;
77     // `?` expands with a `val` binding
78     None?;
79     None
80 }
81
82 pub async fn foo1(_a: i32) {}
83
84 pub async fn foo2(_a: i32, _b: i64) {
85     let _b = _a;
86 }
87
88 fn main() {}