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