]> git.lizzy.rs Git - rust.git/blob - tests/ui/match_single_binding.rs
Auto merge of #4809 - iankronquist:patch-1, r=flip1995
[rust.git] / tests / ui / match_single_binding.rs
1 // run-rustfix
2
3 #![warn(clippy::match_single_binding)]
4 #![allow(clippy::many_single_char_names, clippy::toplevel_ref_arg)]
5
6 struct Point {
7     x: i32,
8     y: i32,
9 }
10
11 fn main() {
12     let a = 1;
13     let b = 2;
14     let c = 3;
15     // Lint
16     match (a, b, c) {
17         (x, y, z) => {
18             println!("{} {} {}", x, y, z);
19         },
20     }
21     // Lint
22     match (a, b, c) {
23         (x, y, z) => println!("{} {} {}", x, y, z),
24     }
25     // Ok
26     match a {
27         2 => println!("2"),
28         _ => println!("Not 2"),
29     }
30     // Ok
31     let d = Some(5);
32     match d {
33         Some(d) => println!("{}", d),
34         _ => println!("None"),
35     }
36     // Lint
37     match a {
38         _ => println!("whatever"),
39     }
40     // Lint
41     match a {
42         _ => {
43             let x = 29;
44             println!("x has a value of {}", x);
45         },
46     }
47     // Lint
48     match a {
49         _ => {
50             let e = 5 * a;
51             if e >= 5 {
52                 println!("e is superior to 5");
53             }
54         },
55     }
56     // Lint
57     let p = Point { x: 0, y: 7 };
58     match p {
59         Point { x, y } => println!("Coords: ({}, {})", x, y),
60     }
61     // Lint
62     match p {
63         Point { x: x1, y: y1 } => println!("Coords: ({}, {})", x1, y1),
64     }
65     // Lint
66     let x = 5;
67     match x {
68         ref r => println!("Got a reference to {}", r),
69     }
70     // Lint
71     let mut x = 5;
72     match x {
73         ref mut mr => println!("Got a mutable reference to {}", mr),
74     }
75 }