-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #67766 - sapir:fix-unused-in-or-pattern-warning, r=ma…
…tthewjasper Fix warning for unused variables in or pattern (issue #67691) Is this a good way to fix it? Also, the tests fail, the "fixed" code output says `{ i, j }` instead of `{ i, j: _ }`, how can I fix that?
- Loading branch information
Showing
7 changed files
with
229 additions
and
52 deletions.
There are no files selected for viewing
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
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
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
86 changes: 86 additions & 0 deletions
86
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,86 @@ | ||
// FIXME: should be run-rustfix, but rustfix doesn't currently support multipart suggestions, see | ||
// #53934 | ||
|
||
#![feature(or_patterns)] | ||
#![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)); | ||
} |
74 changes: 74 additions & 0 deletions
74
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,74 @@ | ||
error: unused variable: `j` | ||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:21:16 | ||
| | ||
LL | A { i, j } | B { i, j } => { | ||
| ^ ^ | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:5: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:31: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:41: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:53: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: unused variable: `i` | ||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:63:24 | ||
| | ||
LL | MixedEnum::A { i } | MixedEnum::B(i) => { | ||
| ^ ^ | ||
| | ||
help: try ignoring the field | ||
| | ||
LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => { | ||
| ^^^^ ^ | ||
|
||
error: unused variable: `i` | ||
--> $DIR/issue-67691-unused-field-in-or-pattern.rs:71:24 | ||
| | ||
LL | MixedEnum::A { ref i } | MixedEnum::B(ref i) => { | ||
| ^^^^^ ^^^^^ | ||
| | ||
help: try ignoring the field | ||
| | ||
LL | MixedEnum::A { i: _ } | MixedEnum::B(_) => { | ||
| ^^^^ ^ | ||
|
||
error: aborting due to 6 previous errors | ||
|
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
Oops, something went wrong.