about summary refs log tree commit diff
path: root/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs
diff options
context:
space:
mode:
authorRust timing bot <rust-timer@users.noreply.github.com>2025-10-04 11:31:00 +0200
committerGitHub <noreply@github.com>2025-10-04 11:31:00 +0200
commit823632bbfbb2941cdc3c69130f19b39ea565a7aa (patch)
tree708d400c34370dfee537670607588999292d0bc3 /tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs
parent7950f244e7ef55b61a83d12f4662be643cd182d6 (diff)
parentd1d7b9472a18780499162b4a91beea729bc2c13b (diff)
downloadrust-try-perf.tar.gz
rust-try-perf.zip
Unrolled build for #147245 try-perf perf-tmp
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.rs')
-rw-r--r--tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs
new file mode 100644
index 00000000000..7d5087fa0ff
--- /dev/null
+++ b/tests/ui/suggestions/only-replace-intended-coma-not-all-in-pattern.rs
@@ -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!(),
+    }
+}