Skip to content

Commit

Permalink
Add tests for issue rust-lang#67691
Browse files Browse the repository at this point in the history
  • Loading branch information
sapir committed Apr 10, 2020
1 parent 94d3463 commit 0c156af
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 0 deletions.
61 changes: 61 additions & 0 deletions src/test/ui/lint/issue-67691-unused-field-in-or-pattern.fixed
Original file line number Diff line number Diff line change
@@ -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 changes: 61 additions & 0 deletions src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs
Original file line number Diff line number Diff line change
@@ -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 }));
}
52 changes: 52 additions & 0 deletions src/test/ui/lint/issue-67691-unused-field-in-or-pattern.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0c156af

Please sign in to comment.