Skip to content

Commit

Permalink
Change bindings_with_variant_name to deny-by-default
Browse files Browse the repository at this point in the history
  • Loading branch information
timrobertsdev authored and Tim Roberts committed Jan 20, 2023
1 parent 51d50ea commit 734f375
Show file tree
Hide file tree
Showing 14 changed files with 54 additions and 63 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_lint_defs/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ declare_lint! {
/// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
/// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
pub BINDINGS_WITH_VARIANT_NAME,
Warn,
Deny,
"detects pattern bindings with the same name as one of the matched variants"
}

Expand Down
5 changes: 2 additions & 3 deletions tests/ui/issues/issue-19100.fixed
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// run-pass
// run-rustfix

#![allow(non_snake_case)]
Expand All @@ -16,11 +15,11 @@ impl Foo {
match self {
&
Foo::Bar if true
//~^ WARN pattern binding `Bar` is named the same as one of the variants of the type `Foo`
//~^ ERROR pattern binding `Bar` is named the same as one of the variants of the type `Foo`
=> println!("bar"),
&
Foo::Baz if false
//~^ WARN pattern binding `Baz` is named the same as one of the variants of the type `Foo`
//~^ ERROR pattern binding `Baz` is named the same as one of the variants of the type `Foo`
=> println!("baz"),
_ => ()
}
Expand Down
5 changes: 2 additions & 3 deletions tests/ui/issues/issue-19100.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// run-pass
// run-rustfix

#![allow(non_snake_case)]
Expand All @@ -16,11 +15,11 @@ impl Foo {
match self {
&
Bar if true
//~^ WARN pattern binding `Bar` is named the same as one of the variants of the type `Foo`
//~^ ERROR pattern binding `Bar` is named the same as one of the variants of the type `Foo`
=> println!("bar"),
&
Baz if false
//~^ WARN pattern binding `Baz` is named the same as one of the variants of the type `Foo`
//~^ ERROR pattern binding `Baz` is named the same as one of the variants of the type `Foo`
=> println!("baz"),
_ => ()
}
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/issues/issue-19100.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
--> $DIR/issue-19100.rs:18:1
error[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
--> $DIR/issue-19100.rs:17:1
|
LL | Bar if true
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
= note: `#[deny(bindings_with_variant_name)]` on by default

warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
--> $DIR/issue-19100.rs:22:1
error[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
--> $DIR/issue-19100.rs:21:1
|
LL | Baz if false
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz`

warning: 2 warnings emitted
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0170`.
2 changes: 1 addition & 1 deletion tests/ui/lint/issue-30302.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ enum Stack<T> {
fn is_empty<T>(s: Stack<T>) -> bool {
match s {
Nil => true,
//~^ WARN pattern binding `Nil` is named the same as one of the variants of the type `Stack`
//~^ ERROR pattern binding `Nil` is named the same as one of the variants of the type `Stack`
_ => false
//~^ ERROR unreachable pattern
}
Expand Down
6 changes: 3 additions & 3 deletions tests/ui/lint/issue-30302.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
warning[E0170]: pattern binding `Nil` is named the same as one of the variants of the type `Stack`
error[E0170]: pattern binding `Nil` is named the same as one of the variants of the type `Stack`
--> $DIR/issue-30302.rs:13:9
|
LL | Nil => true,
| ^^^ help: to match on the variant, qualify the path: `Stack::Nil`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
= note: `#[deny(bindings_with_variant_name)]` on by default

error: unreachable pattern
--> $DIR/issue-30302.rs:15:9
Expand All @@ -21,6 +21,6 @@ note: the lint level is defined here
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted
error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0170`.
6 changes: 3 additions & 3 deletions tests/ui/lint/lint-uppercase-variables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@ fn main() {
match foo::Foo::Foo {
Foo => {}
//~^ ERROR variable `Foo` should have a snake case name
//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo`
//~^^ ERROR `Foo` is named the same as one of the variants of the type `foo::Foo`
//~^^^ WARN unused variable: `Foo`
}

let Foo = foo::Foo::Foo;
//~^ ERROR variable `Foo` should have a snake case name
//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo`
//~^^ ERROR `Foo` is named the same as one of the variants of the type `foo::Foo`
//~^^^ WARN unused variable: `Foo`

fn in_param(Foo: foo::Foo) {}
//~^ ERROR variable `Foo` should have a snake case name
//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo`
//~^^ ERROR `Foo` is named the same as one of the variants of the type `foo::Foo`
//~^^^ WARN unused variable: `Foo`

test(1);
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/lint/lint-uppercase-variables.stderr
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
error[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
--> $DIR/lint-uppercase-variables.rs:22:9
|
LL | Foo => {}
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
= note: `#[deny(bindings_with_variant_name)]` on by default

warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
error[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
--> $DIR/lint-uppercase-variables.rs:28:9
|
LL | let Foo = foo::Foo::Foo;
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`

warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
error[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
--> $DIR/lint-uppercase-variables.rs:33:17
|
LL | fn in_param(Foo: foo::Foo) {}
Expand Down Expand Up @@ -85,6 +85,6 @@ error: variable `Foo` should have a snake case name
LL | fn in_param(Foo: foo::Foo) {}
| ^^^ help: convert the identifier to snake case (notice the capitalization): `foo`

error: aborting due to 6 previous errors; 6 warnings emitted
error: aborting due to 9 previous errors; 3 warnings emitted

For more information about this error, try `rustc --explain E0170`.
4 changes: 2 additions & 2 deletions tests/ui/pattern/issue-14221.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub mod b {
pub fn key(e: ::E) -> &'static str {
match e {
A => "A",
//~^ WARN pattern binding `A` is named the same as one of the variants of the type `E`
//~^ ERROR pattern binding `A` is named the same as one of the variants of the type `E`
B => "B", //~ ERROR: unreachable pattern
//~^ WARN pattern binding `B` is named the same as one of the variants of the type `E`
//~^ ERROR pattern binding `B` is named the same as one of the variants of the type `E`
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/pattern/issue-14221.stderr
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
warning[E0170]: pattern binding `A` is named the same as one of the variants of the type `E`
error[E0170]: pattern binding `A` is named the same as one of the variants of the type `E`
--> $DIR/issue-14221.rs:13:13
|
LL | A => "A",
| ^ help: to match on the variant, qualify the path: `E::A`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
= note: `#[deny(bindings_with_variant_name)]` on by default

warning[E0170]: pattern binding `B` is named the same as one of the variants of the type `E`
error[E0170]: pattern binding `B` is named the same as one of the variants of the type `E`
--> $DIR/issue-14221.rs:15:13
|
LL | B => "B",
Expand All @@ -27,6 +27,6 @@ note: the lint level is defined here
LL | #![deny(unreachable_patterns)]
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 2 warnings emitted
error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0170`.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// Test for issue #67776: binding named the same as enum variant
// should report a warning even when matching against a reference type

// check-pass
// should report an error even when matching against a reference type

#![allow(unused_variables)]
#![allow(non_snake_case)]
Expand All @@ -15,27 +13,27 @@ enum Foo {
fn fn1(e: Foo) {
match e {
Bar => {},
//~^ WARNING named the same as one of the variants of the type `Foo`
//~^ ERROR 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`
//~^ ERROR 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`
//~^ ERROR 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`
//~^ ERROR 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`
//~^ ERROR 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`
//~^ ERROR named the same as one of the variants of the type `Foo`
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
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
error[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:15:9
|
LL | Bar => {},
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
|
= note: `#[warn(bindings_with_variant_name)]` on by default
= note: `#[deny(bindings_with_variant_name)]` on by default

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
error[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:17: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
error[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:24: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
error[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:26: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
error[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:33: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
error[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:35:9
|
LL | Baz => {},
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz`

warning: 6 warnings emitted
error: aborting due to 6 previous errors

For more information about this error, try `rustc --explain E0170`.
3 changes: 1 addition & 2 deletions tests/ui/suggestions/issue-88730.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![allow(unused, nonstandard_style)]
#![deny(bindings_with_variant_name)]

// If an enum has two different variants,
// then it cannot be matched upon in a function argument.
// It still gets a warning, but no suggestions.
// It still gets an error, but no suggestions.
enum Foo {
C,
D,
Expand Down
10 changes: 3 additions & 7 deletions tests/ui/suggestions/issue-88730.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
error[E0170]: pattern binding `C` is named the same as one of the variants of the type `Foo`
--> $DIR/issue-88730.rs:12:8
--> $DIR/issue-88730.rs:11:8
|
LL | fn foo(C: Foo) {}
| ^
|
note: the lint level is defined here
--> $DIR/issue-88730.rs:2:9
|
LL | #![deny(bindings_with_variant_name)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: `#[deny(bindings_with_variant_name)]` on by default

error[E0170]: pattern binding `C` is named the same as one of the variants of the type `Foo`
--> $DIR/issue-88730.rs:15:9
--> $DIR/issue-88730.rs:14:9
|
LL | let C = Foo::D;
| ^
Expand Down

0 comments on commit 734f375

Please sign in to comment.