Skip to content

Commit bb5f43e

Browse files
Rollup merge of rust-lang#104154 - timrobertsdev:deny-by-default-bindings_with_variant_name, r=scottmcm
Change `bindings_with_variant_name` to deny-by-default Changed the `bindings_with_variant_name` lint to deny-by-default and fixed up the affected tests. Addresses rust-lang#103442.
2 parents c3e30f1 + 1cbce72 commit bb5f43e

14 files changed

+55
-64
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,7 @@ declare_lint! {
708708
///
709709
/// ### Example
710710
///
711-
/// ```rust
711+
/// ```rust,compile_fail
712712
/// pub enum Enum {
713713
/// Foo,
714714
/// Bar,
@@ -743,7 +743,7 @@ declare_lint! {
743743
/// [identifier pattern]: https://doc.rust-lang.org/reference/patterns.html#identifier-patterns
744744
/// [path pattern]: https://doc.rust-lang.org/reference/patterns.html#path-patterns
745745
pub BINDINGS_WITH_VARIANT_NAME,
746-
Warn,
746+
Deny,
747747
"detects pattern bindings with the same name as one of the matched variants"
748748
}
749749

tests/ui/issues/issue-19100.fixed

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-pass
21
// run-rustfix
32

43
#![allow(non_snake_case)]
@@ -16,11 +15,11 @@ impl Foo {
1615
match self {
1716
&
1817
Foo::Bar if true
19-
//~^ WARN pattern binding `Bar` is named the same as one of the variants of the type `Foo`
18+
//~^ ERROR pattern binding `Bar` is named the same as one of the variants of the type `Foo`
2019
=> println!("bar"),
2120
&
2221
Foo::Baz if false
23-
//~^ WARN pattern binding `Baz` is named the same as one of the variants of the type `Foo`
22+
//~^ ERROR pattern binding `Baz` is named the same as one of the variants of the type `Foo`
2423
=> println!("baz"),
2524
_ => ()
2625
}

tests/ui/issues/issue-19100.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// run-pass
21
// run-rustfix
32

43
#![allow(non_snake_case)]
@@ -16,11 +15,11 @@ impl Foo {
1615
match self {
1716
&
1817
Bar if true
19-
//~^ WARN pattern binding `Bar` is named the same as one of the variants of the type `Foo`
18+
//~^ ERROR pattern binding `Bar` is named the same as one of the variants of the type `Foo`
2019
=> println!("bar"),
2120
&
2221
Baz if false
23-
//~^ WARN pattern binding `Baz` is named the same as one of the variants of the type `Foo`
22+
//~^ ERROR pattern binding `Baz` is named the same as one of the variants of the type `Foo`
2423
=> println!("baz"),
2524
_ => ()
2625
}

tests/ui/issues/issue-19100.stderr

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
2-
--> $DIR/issue-19100.rs:18:1
1+
error[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
2+
--> $DIR/issue-19100.rs:17:1
33
|
44
LL | Bar if true
55
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
66
|
7-
= note: `#[warn(bindings_with_variant_name)]` on by default
7+
= note: `#[deny(bindings_with_variant_name)]` on by default
88

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

15-
warning: 2 warnings emitted
15+
error: aborting due to 2 previous errors
1616

1717
For more information about this error, try `rustc --explain E0170`.

tests/ui/lint/issue-30302.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum Stack<T> {
1111
fn is_empty<T>(s: Stack<T>) -> bool {
1212
match s {
1313
Nil => true,
14-
//~^ WARN pattern binding `Nil` is named the same as one of the variants of the type `Stack`
14+
//~^ ERROR pattern binding `Nil` is named the same as one of the variants of the type `Stack`
1515
_ => false
1616
//~^ ERROR unreachable pattern
1717
}

tests/ui/lint/issue-30302.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
warning[E0170]: pattern binding `Nil` is named the same as one of the variants of the type `Stack`
1+
error[E0170]: pattern binding `Nil` is named the same as one of the variants of the type `Stack`
22
--> $DIR/issue-30302.rs:13:9
33
|
44
LL | Nil => true,
55
| ^^^ help: to match on the variant, qualify the path: `Stack::Nil`
66
|
7-
= note: `#[warn(bindings_with_variant_name)]` on by default
7+
= note: `#[deny(bindings_with_variant_name)]` on by default
88

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

24-
error: aborting due to previous error; 1 warning emitted
24+
error: aborting due to 2 previous errors
2525

2626
For more information about this error, try `rustc --explain E0170`.

tests/ui/lint/lint-uppercase-variables.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ fn main() {
2121
match foo::Foo::Foo {
2222
Foo => {}
2323
//~^ ERROR variable `Foo` should have a snake case name
24-
//~^^ WARN `Foo` is named the same as one of the variants of the type `foo::Foo`
24+
//~^^ ERROR `Foo` is named the same as one of the variants of the type `foo::Foo`
2525
//~^^^ WARN unused variable: `Foo`
2626
}
2727

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

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

3838
test(1);

tests/ui/lint/lint-uppercase-variables.stderr

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
1-
warning[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
1+
error[E0170]: pattern binding `Foo` is named the same as one of the variants of the type `foo::Foo`
22
--> $DIR/lint-uppercase-variables.rs:22:9
33
|
44
LL | Foo => {}
55
| ^^^ help: to match on the variant, qualify the path: `foo::Foo::Foo`
66
|
7-
= note: `#[warn(bindings_with_variant_name)]` on by default
7+
= note: `#[deny(bindings_with_variant_name)]` on by default
88

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

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

88-
error: aborting due to 6 previous errors; 6 warnings emitted
88+
error: aborting due to 9 previous errors; 3 warnings emitted
8989

9090
For more information about this error, try `rustc --explain E0170`.

tests/ui/pattern/issue-14221.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ pub mod b {
1111
pub fn key(e: ::E) -> &'static str {
1212
match e {
1313
A => "A",
14-
//~^ WARN pattern binding `A` is named the same as one of the variants of the type `E`
14+
//~^ ERROR pattern binding `A` is named the same as one of the variants of the type `E`
1515
B => "B", //~ ERROR: unreachable pattern
16-
//~^ WARN pattern binding `B` is named the same as one of the variants of the type `E`
16+
//~^ ERROR pattern binding `B` is named the same as one of the variants of the type `E`
1717
}
1818
}
1919
}

tests/ui/pattern/issue-14221.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
warning[E0170]: pattern binding `A` is named the same as one of the variants of the type `E`
1+
error[E0170]: pattern binding `A` is named the same as one of the variants of the type `E`
22
--> $DIR/issue-14221.rs:13:13
33
|
44
LL | A => "A",
55
| ^ help: to match on the variant, qualify the path: `E::A`
66
|
7-
= note: `#[warn(bindings_with_variant_name)]` on by default
7+
= note: `#[deny(bindings_with_variant_name)]` on by default
88

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

30-
error: aborting due to previous error; 2 warnings emitted
30+
error: aborting due to 3 previous errors
3131

3232
For more information about this error, try `rustc --explain E0170`.

tests/ui/pattern/issue-67776-match-same-name-enum-variant-refs.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
// Test for issue #67776: binding named the same as enum variant
2-
// should report a warning even when matching against a reference type
3-
4-
// check-pass
2+
// should report an error even when matching against a reference type
53

64
#![allow(unused_variables)]
75
#![allow(non_snake_case)]
@@ -15,27 +13,27 @@ enum Foo {
1513
fn fn1(e: Foo) {
1614
match e {
1715
Bar => {},
18-
//~^ WARNING named the same as one of the variants of the type `Foo`
16+
//~^ ERROR named the same as one of the variants of the type `Foo`
1917
Baz => {},
20-
//~^ WARNING named the same as one of the variants of the type `Foo`
18+
//~^ ERROR named the same as one of the variants of the type `Foo`
2119
}
2220
}
2321

2422
fn fn2(e: &Foo) {
2523
match e {
2624
Bar => {},
27-
//~^ WARNING named the same as one of the variants of the type `Foo`
25+
//~^ ERROR named the same as one of the variants of the type `Foo`
2826
Baz => {},
29-
//~^ WARNING named the same as one of the variants of the type `Foo`
27+
//~^ ERROR named the same as one of the variants of the type `Foo`
3028
}
3129
}
3230

3331
fn fn3(e: &mut &&mut Foo) {
3432
match e {
3533
Bar => {},
36-
//~^ WARNING named the same as one of the variants of the type `Foo`
34+
//~^ ERROR named the same as one of the variants of the type `Foo`
3735
Baz => {},
38-
//~^ WARNING named the same as one of the variants of the type `Foo`
36+
//~^ ERROR named the same as one of the variants of the type `Foo`
3937
}
4038
}
4139

Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
1-
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
2-
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:17:9
1+
error[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
2+
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:15:9
33
|
44
LL | Bar => {},
55
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
66
|
7-
= note: `#[warn(bindings_with_variant_name)]` on by default
7+
= note: `#[deny(bindings_with_variant_name)]` on by default
88

9-
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
10-
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:19:9
9+
error[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
10+
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:17:9
1111
|
1212
LL | Baz => {},
1313
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz`
1414

15-
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
16-
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:26:9
15+
error[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
16+
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:24:9
1717
|
1818
LL | Bar => {},
1919
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
2020

21-
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
22-
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:28:9
21+
error[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
22+
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:26:9
2323
|
2424
LL | Baz => {},
2525
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz`
2626

27-
warning[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
28-
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:35:9
27+
error[E0170]: pattern binding `Bar` is named the same as one of the variants of the type `Foo`
28+
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:33:9
2929
|
3030
LL | Bar => {},
3131
| ^^^ help: to match on the variant, qualify the path: `Foo::Bar`
3232

33-
warning[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
34-
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:37:9
33+
error[E0170]: pattern binding `Baz` is named the same as one of the variants of the type `Foo`
34+
--> $DIR/issue-67776-match-same-name-enum-variant-refs.rs:35:9
3535
|
3636
LL | Baz => {},
3737
| ^^^ help: to match on the variant, qualify the path: `Foo::Baz`
3838

39-
warning: 6 warnings emitted
39+
error: aborting due to 6 previous errors
4040

4141
For more information about this error, try `rustc --explain E0170`.

tests/ui/suggestions/issue-88730.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
#![allow(unused, nonstandard_style)]
2-
#![deny(bindings_with_variant_name)]
32

43
// If an enum has two different variants,
54
// then it cannot be matched upon in a function argument.
6-
// It still gets a warning, but no suggestions.
5+
// It still gets an error, but no suggestions.
76
enum Foo {
87
C,
98
D,

tests/ui/suggestions/issue-88730.stderr

+3-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
error[E0170]: pattern binding `C` is named the same as one of the variants of the type `Foo`
2-
--> $DIR/issue-88730.rs:12:8
2+
--> $DIR/issue-88730.rs:11:8
33
|
44
LL | fn foo(C: Foo) {}
55
| ^
66
|
7-
note: the lint level is defined here
8-
--> $DIR/issue-88730.rs:2:9
9-
|
10-
LL | #![deny(bindings_with_variant_name)]
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
7+
= note: `#[deny(bindings_with_variant_name)]` on by default
128

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

0 commit comments

Comments
 (0)