Skip to content

Commit 934ad74

Browse files
committed
regression test
1 parent a08228d commit 934ad74

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ run-rustfix
2+
3+
// Regression test for issue #143330.
4+
// Ensure we suggest to replace only the intended bar with a comma, not all bars in the pattern.
5+
6+
fn main() {
7+
struct Foo { x: i32, ch: char }
8+
let pos = Foo { x: 2, ch: 'x' };
9+
match pos {
10+
// All commas here were replaced with bars.
11+
// Foo { x: 2 | ch: ' |' } | Foo { x: 3 | ch: '@' } => (),
12+
(Foo { x: 2, ch: ',' } | Foo { x: 3, ch: '@' }) => (),
13+
//~^ ERROR unexpected `,` in pattern
14+
//~| HELP try adding parentheses to match on a tuple...
15+
//~| HELP ...or a vertical bar to match on alternative
16+
_ => todo!(),
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ run-rustfix
2+
3+
// Regression test for issue #143330.
4+
// Ensure we suggest to replace only the intended bar with a comma, not all bars in the pattern.
5+
6+
fn main() {
7+
struct Foo { x: i32, ch: char }
8+
let pos = Foo { x: 2, ch: 'x' };
9+
match pos {
10+
// All commas here were replaced with bars.
11+
// Foo { x: 2 | ch: ' |' } | Foo { x: 3 | ch: '@' } => (),
12+
Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' } => (),
13+
//~^ ERROR unexpected `,` in pattern
14+
//~| HELP try adding parentheses to match on a tuple...
15+
//~| HELP ...or a vertical bar to match on alternative
16+
_ => todo!(),
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: unexpected `,` in pattern
2+
--> $DIR/only-replace-intended-bar-not-all-in-pattern.rs:12:30
3+
|
4+
LL | Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' } => (),
5+
| ^
6+
|
7+
help: try adding parentheses to match on a tuple...
8+
|
9+
LL | (Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' }) => (),
10+
| + +
11+
help: ...or a vertical bar to match on alternative
12+
|
13+
LL - Foo { x: 2, ch: ',' }, Foo { x: 3, ch: '@' } => (),
14+
LL + Foo { x: 2, ch: ',' } | Foo { x: 3, ch: '@' } => (),
15+
|
16+
17+
error: aborting due to 1 previous error
18+

0 commit comments

Comments
 (0)