Skip to content

Commit 0c156af

Browse files
committed
Add tests for issue rust-lang#67691
1 parent 94d3463 commit 0c156af

3 files changed

+174
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// run-rustfix
2+
3+
#![feature(or_patterns)]
4+
#![deny(unused)]
5+
6+
pub enum MyEnum {
7+
A { i: i32, j: i32 },
8+
B { i: i32, j: i32 },
9+
}
10+
11+
pub fn no_ref(x: MyEnum) {
12+
use MyEnum::*;
13+
14+
match x {
15+
A { i, j: _ } | B { i, j: _ } => { //~ ERROR unused variable
16+
println!("{}", i);
17+
}
18+
}
19+
}
20+
21+
pub fn with_ref(x: MyEnum) {
22+
use MyEnum::*;
23+
24+
match x {
25+
A { i, j: _ } | B { i, j: _ } => { //~ ERROR unused variable
26+
println!("{}", i);
27+
}
28+
}
29+
}
30+
31+
pub fn inner_no_ref(x: Option<MyEnum>) {
32+
use MyEnum::*;
33+
34+
match x {
35+
Some(A { i, j: _ } | B { i, j: _ }) => { //~ ERROR unused variable
36+
println!("{}", i);
37+
}
38+
39+
_ => {}
40+
}
41+
}
42+
43+
pub fn inner_with_ref(x: Option<MyEnum>) {
44+
use MyEnum::*;
45+
46+
match x {
47+
Some(A { i, j: _ } | B { i, j: _ }) => { //~ ERROR unused variable
48+
println!("{}", i);
49+
}
50+
51+
_ => {}
52+
}
53+
}
54+
55+
pub fn main() {
56+
no_ref(MyEnum::A { i: 1, j: 2 });
57+
with_ref(MyEnum::A { i: 1, j: 2 });
58+
59+
inner_no_ref(Some(MyEnum::A { i: 1, j: 2 }));
60+
inner_with_ref(Some(MyEnum::A { i: 1, j: 2 }));
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// run-rustfix
2+
3+
#![feature(or_patterns)]
4+
#![deny(unused)]
5+
6+
pub enum MyEnum {
7+
A { i: i32, j: i32 },
8+
B { i: i32, j: i32 },
9+
}
10+
11+
pub fn no_ref(x: MyEnum) {
12+
use MyEnum::*;
13+
14+
match x {
15+
A { i, j } | B { i, j } => { //~ ERROR unused variable
16+
println!("{}", i);
17+
}
18+
}
19+
}
20+
21+
pub fn with_ref(x: MyEnum) {
22+
use MyEnum::*;
23+
24+
match x {
25+
A { i, ref j } | B { i, ref j } => { //~ ERROR unused variable
26+
println!("{}", i);
27+
}
28+
}
29+
}
30+
31+
pub fn inner_no_ref(x: Option<MyEnum>) {
32+
use MyEnum::*;
33+
34+
match x {
35+
Some(A { i, j } | B { i, j }) => { //~ ERROR unused variable
36+
println!("{}", i);
37+
}
38+
39+
_ => {}
40+
}
41+
}
42+
43+
pub fn inner_with_ref(x: Option<MyEnum>) {
44+
use MyEnum::*;
45+
46+
match x {
47+
Some(A { i, ref j } | B { i, ref j }) => { //~ ERROR unused variable
48+
println!("{}", i);
49+
}
50+
51+
_ => {}
52+
}
53+
}
54+
55+
pub fn main() {
56+
no_ref(MyEnum::A { i: 1, j: 2 });
57+
with_ref(MyEnum::A { i: 1, j: 2 });
58+
59+
inner_no_ref(Some(MyEnum::A { i: 1, j: 2 }));
60+
inner_with_ref(Some(MyEnum::A { i: 1, j: 2 }));
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error: unused variable: `j`
2+
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:15:16
3+
|
4+
LL | A { i, j } | B { i, j } => {
5+
| ^ ^
6+
|
7+
note: the lint level is defined here
8+
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:4:9
9+
|
10+
LL | #![deny(unused)]
11+
| ^^^^^^
12+
= note: `#[deny(unused_variables)]` implied by `#[deny(unused)]`
13+
help: try ignoring the field
14+
|
15+
LL | A { i, j: _ } | B { i, j: _ } => {
16+
| ^^^^ ^^^^
17+
18+
error: unused variable: `j`
19+
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:25:16
20+
|
21+
LL | A { i, ref j } | B { i, ref j } => {
22+
| ^^^^^ ^^^^^
23+
|
24+
help: try ignoring the field
25+
|
26+
LL | A { i, j: _ } | B { i, j: _ } => {
27+
| ^^^^ ^^^^
28+
29+
error: unused variable: `j`
30+
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:35:21
31+
|
32+
LL | Some(A { i, j } | B { i, j }) => {
33+
| ^ ^
34+
|
35+
help: try ignoring the field
36+
|
37+
LL | Some(A { i, j: _ } | B { i, j: _ }) => {
38+
| ^^^^ ^^^^
39+
40+
error: unused variable: `j`
41+
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:47:21
42+
|
43+
LL | Some(A { i, ref j } | B { i, ref j }) => {
44+
| ^^^^^ ^^^^^
45+
|
46+
help: try ignoring the field
47+
|
48+
LL | Some(A { i, j: _ } | B { i, j: _ }) => {
49+
| ^^^^ ^^^^
50+
51+
error: aborting due to 5 previous errors
52+

0 commit comments

Comments
 (0)