]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs
Merge commit '70c0f90453701e7d6d9b99aaa1fc6a765937b736' into clippyup
[rust.git] / src / test / ui / lint / issue-67691-unused-field-in-or-pattern.rs
1 // FIXME: should be run-rustfix, but rustfix doesn't currently support multipart suggestions, see
2 // #53934
3
4 #![feature(or_patterns)]
5 #![deny(unused)]
6
7 pub enum MyEnum {
8     A { i: i32, j: i32 },
9     B { i: i32, j: i32 },
10 }
11
12 pub enum MixedEnum {
13     A { i: i32 },
14     B(i32),
15 }
16
17 pub fn no_ref(x: MyEnum) {
18     use MyEnum::*;
19
20     match x {
21         A { i, j } | B { i, j } => { //~ ERROR unused variable
22             println!("{}", i);
23         }
24     }
25 }
26
27 pub fn with_ref(x: MyEnum) {
28     use MyEnum::*;
29
30     match x {
31         A { i, ref j } | B { i, ref j } => { //~ ERROR unused variable
32             println!("{}", i);
33         }
34     }
35 }
36
37 pub fn inner_no_ref(x: Option<MyEnum>) {
38     use MyEnum::*;
39
40     match x {
41         Some(A { i, j } | B { i, j }) => { //~ ERROR unused variable
42             println!("{}", i);
43         }
44
45         _ => {}
46     }
47 }
48
49 pub fn inner_with_ref(x: Option<MyEnum>) {
50     use MyEnum::*;
51
52     match x {
53         Some(A { i, ref j } | B { i, ref j }) => { //~ ERROR unused variable
54             println!("{}", i);
55         }
56
57         _ => {}
58     }
59 }
60
61 pub fn mixed_no_ref(x: MixedEnum) {
62     match x {
63         MixedEnum::A { i } | MixedEnum::B(i) => { //~ ERROR unused variable
64             println!("match");
65         }
66     }
67 }
68
69 pub fn mixed_with_ref(x: MixedEnum) {
70     match x {
71         MixedEnum::A { ref i } | MixedEnum::B(ref i) => { //~ ERROR unused variable
72             println!("match");
73         }
74     }
75 }
76
77 pub fn main() {
78     no_ref(MyEnum::A { i: 1, j: 2 });
79     with_ref(MyEnum::A { i: 1, j: 2 });
80
81     inner_no_ref(Some(MyEnum::A { i: 1, j: 2 }));
82     inner_with_ref(Some(MyEnum::A { i: 1, j: 2 }));
83
84     mixed_no_ref(MixedEnum::B(5));
85     mixed_with_ref(MixedEnum::B(5));
86 }