diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-10-03 21:10:31 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-03 21:10:31 +0200 |
| commit | 2e06dcdbeb45f1df32d97d7a85b923d8996b9592 (patch) | |
| tree | 74e51057a8ac72ad7c88dace1d2b0b5a7ccb3d8d /tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed | |
| parent | f437c86ef829e43c6aa27641f53040a999a092af (diff) | |
| parent | d1d7b9472a18780499162b4a91beea729bc2c13b (diff) | |
| download | rust-2e06dcdbeb45f1df32d97d7a85b923d8996b9592.tar.gz rust-2e06dcdbeb45f1df32d97d7a85b923d8996b9592.zip | |
Rollup merge of #147245 - karolzwolak:only-replace-intended-bar-not-all-in-pattern, r=lcnr
only replace the intended comma in pattern suggestions Only suggest to replace the intended comma, not all bars in the pattern. Fixes rust-lang/rust#143330. This continues rust-lang/rust#143331, the credit for making the fix goes to `@A4-Tacks.` I just blessed tests and added a regression test.
Diffstat (limited to 'tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed')
| -rw-r--r-- | tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed new file mode 100644 index 00000000000..0258f868f00 --- /dev/null +++ b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.fixed @@ -0,0 +1,18 @@ +//@ run-rustfix + +// Regression test for issue #143330. +// Ensure we suggest to replace only the intended coma with a bar, not all commas in the pattern. + +fn main() { + struct Foo { x: i32, ch: char } + let pos = Foo { x: 2, ch: 'x' }; + match pos { + // All commas here were replaced with bars. + // Foo { x: 2 | ch: ' |' } | Foo { x: 3 | ch: '@' } => (), + (Foo { x: 2, ch: ',' } | Foo { x: 3, ch: '@' }) => (), + //~^ ERROR unexpected `,` in pattern + //~| HELP try adding parentheses to match on a tuple... + //~| HELP ...or a vertical bar to match on alternative + _ => todo!(), + } +} |
