]> git.proxmox.com Git - rustc.git/blob - src/tools/clippy/tests/ui/match_single_binding.fixed
New upstream version 1.61.0+dfsg1
[rustc.git] / src / tools / clippy / tests / ui / match_single_binding.fixed
1 // run-rustfix
2
3 #![warn(clippy::match_single_binding)]
4 #![allow(unused_variables, clippy::toplevel_ref_arg)]
5
6 struct Point {
7 x: i32,
8 y: i32,
9 }
10
11 fn coords() -> Point {
12 Point { x: 1, y: 2 }
13 }
14
15 macro_rules! foo {
16 ($param:expr) => {
17 match $param {
18 _ => println!("whatever"),
19 }
20 };
21 }
22
23 fn main() {
24 let a = 1;
25 let b = 2;
26 let c = 3;
27 // Lint
28 let (x, y, z) = (a, b, c);
29 {
30 println!("{} {} {}", x, y, z);
31 }
32 // Lint
33 let (x, y, z) = (a, b, c);
34 println!("{} {} {}", x, y, z);
35 // Ok
36 foo!(a);
37 // Ok
38 match a {
39 2 => println!("2"),
40 _ => println!("Not 2"),
41 }
42 // Ok
43 let d = Some(5);
44 match d {
45 Some(d) => println!("{}", d),
46 _ => println!("None"),
47 }
48 // Lint
49 println!("whatever");
50 // Lint
51 {
52 let x = 29;
53 println!("x has a value of {}", x);
54 }
55 // Lint
56 {
57 let e = 5 * a;
58 if e >= 5 {
59 println!("e is superior to 5");
60 }
61 }
62 // Lint
63 let p = Point { x: 0, y: 7 };
64 let Point { x, y } = p;
65 println!("Coords: ({}, {})", x, y);
66 // Lint
67 let Point { x: x1, y: y1 } = p;
68 println!("Coords: ({}, {})", x1, y1);
69 // Lint
70 let x = 5;
71 let ref r = x;
72 println!("Got a reference to {}", r);
73 // Lint
74 let mut x = 5;
75 let ref mut mr = x;
76 println!("Got a mutable reference to {}", mr);
77 // Lint
78 let Point { x, y } = coords();
79 let product = x * y;
80 // Lint
81 let v = vec![Some(1), Some(2), Some(3), Some(4)];
82 #[allow(clippy::let_and_return)]
83 let _ = v
84 .iter()
85 .map(|i| {
86 let unwrapped = i.unwrap();
87 unwrapped
88 })
89 .collect::<Vec<u8>>();
90 // Ok
91 let x = 1;
92 match x {
93 #[cfg(disabled_feature)]
94 0 => println!("Disabled branch"),
95 _ => println!("Enabled branch"),
96 }
97
98 // Ok
99 let x = 1;
100 let y = 1;
101 match match y {
102 0 => 1,
103 _ => 2,
104 } {
105 #[cfg(disabled_feature)]
106 0 => println!("Array index start"),
107 _ => println!("Not an array index start"),
108 }
109
110 // Lint
111 let x = 1;
112 println!("Not an array index start");
113 }