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