forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
174 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
src/test/ui/lint/issue-67691-unused-field-in-or-pattern.fixed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
src/test/ui/lint/issue-67691-unused-field-in-or-pattern.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
52
src/test/ui/lint/issue-67691-unused-field-in-or-pattern.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|