forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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 rust-lang#67783 - LeSeulArtichaut:pattern-ref-warning…
…, r=Centril Warn for bindings named same as variants when matching against a borrow Fixes rust-lang#67776
- Loading branch information
Showing
3 changed files
with
79 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.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,42 @@ | ||
// Test for issue #67776: binding named the same as enum variant | ||
// should report a warning even when matching against a reference type | ||
|
||
// check-pass | ||
|
||
#![allow(unused_variables)] | ||
#![allow(non_snake_case)] | ||
|
||
enum Foo { | ||
Bar, | ||
Baz, | ||
} | ||
|
||
|
||
fn fn1(e: Foo) { | ||
match e { | ||
Bar => {}, | ||
//~^ WARNING named the same as one of the variants of the type `Foo` | ||
Baz => {}, | ||
//~^ WARNING named the same as one of the variants of the type `Foo` | ||
} | ||
} | ||
|
||
fn fn2(e: &Foo) { | ||
match e { | ||
Bar => {}, | ||
//~^ WARNING named the same as one of the variants of the type `Foo` | ||
Baz => {}, | ||
//~^ WARNING named the same as one of the variants of the type `Foo` | ||
} | ||
} | ||
|
||
fn fn3(e: &mut &&mut Foo) { | ||
match e { | ||
Bar => {}, | ||
//~^ WARNING named the same as one of the variants of the type `Foo` | ||
Baz => {}, | ||
//~^ WARNING named the same as one of the variants of the type `Foo` | ||
} | ||
} | ||
|
||
fn main() {} |
36 changes: 36 additions & 0 deletions
36
src/test/ui/pattern/issue-67776-match-same-name-enum-variant-refs.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,36 @@ | ||
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:17:9 | ||
| | ||
LL | Bar => {}, | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar` | ||
|
||
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:19:9 | ||
| | ||
LL | Baz => {}, | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz` | ||
|
||
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:26:9 | ||
| | ||
LL | Bar => {}, | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar` | ||
|
||
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:28:9 | ||
| | ||
LL | Baz => {}, | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz` | ||
|
||
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:35:9 | ||
| | ||
LL | Bar => {}, | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar` | ||
|
||
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo` | ||
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:37:9 | ||
| | ||
LL | Baz => {}, | ||
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz` | ||
|