Skip to content

Commit bd0ea61

Browse files
committed
Add test for typo in or-pattern binding
1 parent 8dbdb17 commit bd0ea61

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Issue #51976
2+
//@ run-rustfix
3+
#![deny(unused_variables)] //~ NOTE: the lint level is defined here
4+
enum Lol {
5+
Foo,
6+
Bar,
7+
}
8+
9+
fn foo(x: (Lol, Lol)) {
10+
use Lol::*;
11+
match x {
12+
(Foo, Bar) | (Bar, Foo) => {}
13+
//~^ ERROR: variable `Ban` is not bound in all patterns
14+
//~| HELP: you might have meant to use the similarly named previously used binding `Bar`
15+
//~| NOTE: pattern doesn't bind `Ban`
16+
//~| NOTE: variable not in all patterns
17+
//~| ERROR: variable `Ban` is assigned to, but never used
18+
//~| NOTE: consider using `_Ban` instead
19+
_ => {}
20+
}
21+
}
22+
23+
fn main() {
24+
use Lol::*;
25+
foo((Foo, Bar));
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Issue #51976
2+
//@ run-rustfix
3+
#![deny(unused_variables)] //~ NOTE: the lint level is defined here
4+
enum Lol {
5+
Foo,
6+
Bar,
7+
}
8+
9+
fn foo(x: (Lol, Lol)) {
10+
use Lol::*;
11+
match x {
12+
(Foo, Bar) | (Ban, Foo) => {}
13+
//~^ ERROR: variable `Ban` is not bound in all patterns
14+
//~| HELP: you might have meant to use the similarly named previously used binding `Bar`
15+
//~| NOTE: pattern doesn't bind `Ban`
16+
//~| NOTE: variable not in all patterns
17+
//~| ERROR: variable `Ban` is assigned to, but never used
18+
//~| NOTE: consider using `_Ban` instead
19+
_ => {}
20+
}
21+
}
22+
23+
fn main() {
24+
use Lol::*;
25+
foo((Foo, Bar));
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0408]: variable `Ban` is not bound in all patterns
2+
--> $DIR/binding-typo.rs:12:9
3+
|
4+
LL | (Foo, Bar) | (Ban, Foo) => {}
5+
| ^^^^^^^^^^ --- variable not in all patterns
6+
| |
7+
| pattern doesn't bind `Ban`
8+
|
9+
help: you might have meant to use the similarly named previously used binding `Bar`
10+
|
11+
LL - (Foo, Bar) | (Ban, Foo) => {}
12+
LL + (Foo, Bar) | (Bar, Foo) => {}
13+
|
14+
15+
error: variable `Ban` is assigned to, but never used
16+
--> $DIR/binding-typo.rs:12:23
17+
|
18+
LL | (Foo, Bar) | (Ban, Foo) => {}
19+
| ^^^
20+
|
21+
= note: consider using `_Ban` instead
22+
note: the lint level is defined here
23+
--> $DIR/binding-typo.rs:3:9
24+
|
25+
LL | #![deny(unused_variables)]
26+
| ^^^^^^^^^^^^^^^^
27+
28+
error: aborting due to 2 previous errors
29+
30+
For more information about this error, try `rustc --explain E0408`.

0 commit comments

Comments
 (0)