]> git.lizzy.rs Git - rust.git/blob - src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs
Rollup merge of #87180 - notriddle:notriddle/sidebar-keyboard-mobile, r=GuillaumeGomez
[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 #![deny(unused)]
5
6 pub enum MyEnum {
7     A { i: i32, j: i32 },
8     B { i: i32, j: i32 },
9 }
10
11 pub enum MixedEnum {
12     A { i: i32 },
13     B(i32),
14 }
15
16 pub fn no_ref(x: MyEnum) {
17     use MyEnum::*;
18
19     match x {
20         A { i, j } | B { i, j } => { //~ ERROR unused variable
21             println!("{}", i);
22         }
23     }
24 }
25
26 pub fn with_ref(x: MyEnum) {
27     use MyEnum::*;
28
29     match x {
30         A { i, ref j } | B { i, ref j } => { //~ ERROR unused variable
31             println!("{}", i);
32         }
33     }
34 }
35
36 pub fn inner_no_ref(x: Option<MyEnum>) {
37     use MyEnum::*;
38
39     match x {
40         Some(A { i, j } | B { i, j }) => { //~ ERROR unused variable
41             println!("{}", i);
42         }
43
44         _ => {}
45     }
46 }
47
48 pub fn inner_with_ref(x: Option<MyEnum>) {
49     use MyEnum::*;
50
51     match x {
52         Some(A { i, ref j } | B { i, ref j }) => { //~ ERROR unused variable
53             println!("{}", i);
54         }
55
56         _ => {}
57     }
58 }
59
60 pub fn mixed_no_ref(x: MixedEnum) {
61     match x {
62         MixedEnum::A { i } | MixedEnum::B(i) => { //~ ERROR unused variable
63             println!("match");
64         }
65     }
66 }
67
68 pub fn mixed_with_ref(x: MixedEnum) {
69     match x {
70         MixedEnum::A { ref i } | MixedEnum::B(ref i) => { //~ ERROR unused variable
71             println!("match");
72         }
73     }
74 }
75
76 pub fn main() {
77     no_ref(MyEnum::A { i: 1, j: 2 });
78     with_ref(MyEnum::A { i: 1, j: 2 });
79
80     inner_no_ref(Some(MyEnum::A { i: 1, j: 2 }));
81     inner_with_ref(Some(MyEnum::A { i: 1, j: 2 }));
82
83     mixed_no_ref(MixedEnum::B(5));
84     mixed_with_ref(MixedEnum::B(5));
85 }