]> git.lizzy.rs Git - rust.git/blob - tests/ui/match_single_binding.fixed
Auto merge of #5350 - ThibsG:FixSingleBindingClosure, r=flip1995
[rust.git] / tests / ui / match_single_binding.fixed
1 // run-rustfix
2
3 #![warn(clippy::match_single_binding)]
4 #![allow(unused_variables, clippy::many_single_char_names, 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 fn main() {
16     let a = 1;
17     let b = 2;
18     let c = 3;
19     // Lint
20     let (x, y, z) = (a, b, c);
21     {
22         println!("{} {} {}", x, y, z);
23     }
24     // Lint
25     let (x, y, z) = (a, b, c);
26     println!("{} {} {}", x, y, z);
27     // Ok
28     match a {
29         2 => println!("2"),
30         _ => println!("Not 2"),
31     }
32     // Ok
33     let d = Some(5);
34     match d {
35         Some(d) => println!("{}", d),
36         _ => println!("None"),
37     }
38     // Lint
39     println!("whatever");
40     // Lint
41     {
42         let x = 29;
43         println!("x has a value of {}", x);
44     }
45     // Lint
46     {
47         let e = 5 * a;
48         if e >= 5 {
49             println!("e is superior to 5");
50         }
51     }
52     // Lint
53     let p = Point { x: 0, y: 7 };
54     let Point { x, y } = p;
55     println!("Coords: ({}, {})", x, y);
56     // Lint
57     let Point { x: x1, y: y1 } = p;
58     println!("Coords: ({}, {})", x1, y1);
59     // Lint
60     let x = 5;
61     let ref r = x;
62     println!("Got a reference to {}", r);
63     // Lint
64     let mut x = 5;
65     let ref mut mr = x;
66     println!("Got a mutable reference to {}", mr);
67     // Lint
68     let Point { x, y } = coords();
69     let product = x * y;
70     // Lint
71     let v = vec![Some(1), Some(2), Some(3), Some(4)];
72     #[allow(clippy::let_and_return)]
73     let _ = v
74         .iter()
75         .map(|i| {
76             let unwrapped = i.unwrap();
77             unwrapped
78         })
79         .collect::<Vec<u8>>();
80 }