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