Add tests for issue #67691
This commit is contained in:
parent
94d346360d
commit
0c156af20d
@ -0,0 +1,61 @@
|
||||
// run-rustfix
|
||||
|
||||
#![feature(or_patterns)]
|
||||
#![deny(unused)]
|
||||
|
||||
pub enum MyEnum {
|
||||
A { i: i32, j: i32 },
|
||||
B { i: i32, j: 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, j: _ } | B { i, 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, j: _ } | B { i, j: _ }) => { //~ ERROR unused variable
|
||||
println!("{}", i);
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
|
||||
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 }));
|
||||
}
|
61
src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs
Normal file
61
src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs
Normal file
@ -0,0 +1,61 @@
|
||||
// run-rustfix
|
||||
|
||||
#![feature(or_patterns)]
|
||||
#![deny(unused)]
|
||||
|
||||
pub enum MyEnum {
|
||||
A { i: i32, j: i32 },
|
||||
B { i: i32, j: 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 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 }));
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
error: unused variable: `j`
|
||||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:15:16
|
||||
|
|
||||
LL | A { i, j } | B { i, j } => {
|
||||
| ^ ^
|
||||
|
|
||||
note: the lint level is defined here
|
||||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:4:9
|
||||
|
|
||||
LL | #![deny(unused)]
|
||||
| ^^^^^^
|
||||
= note: `#[deny(unused_variables)]` implied by `#[deny(unused)]`
|
||||
help: try ignoring the field
|
||||
|
|
||||
LL | A { i, j: _ } | B { i, j: _ } => {
|
||||
| ^^^^ ^^^^
|
||||
|
||||
error: unused variable: `j`
|
||||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:25:16
|
||||
|
|
||||
LL | A { i, ref j } | B { i, ref j } => {
|
||||
| ^^^^^ ^^^^^
|
||||
|
|
||||
help: try ignoring the field
|
||||
|
|
||||
LL | A { i, j: _ } | B { i, j: _ } => {
|
||||
| ^^^^ ^^^^
|
||||
|
||||
error: unused variable: `j`
|
||||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:35:21
|
||||
|
|
||||
LL | Some(A { i, j } | B { i, j }) => {
|
||||
| ^ ^
|
||||
|
|
||||
help: try ignoring the field
|
||||
|
|
||||
LL | Some(A { i, j: _ } | B { i, j: _ }) => {
|
||||
| ^^^^ ^^^^
|
||||
|
||||
error: unused variable: `j`
|
||||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:47:21
|
||||
|
|
||||
LL | Some(A { i, ref j } | B { i, ref j }) => {
|
||||
| ^^^^^ ^^^^^
|
||||
|
|
||||
help: try ignoring the field
|
||||
|
|
||||
LL | Some(A { i, j: _ } | B { i, j: _ }) => {
|
||||
| ^^^^ ^^^^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user