diff options
| author | Rust timing bot <rust-timer@users.noreply.github.com> | 2025-10-04 11:31:00 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-10-04 11:31:00 +0200 |
| commit | 823632bbfbb2941cdc3c69130f19b39ea565a7aa (patch) | |
| tree | 708d400c34370dfee537670607588999292d0bc3 /compiler | |
| parent | 7950f244e7ef55b61a83d12f4662be643cd182d6 (diff) | |
| parent | d1d7b9472a18780499162b4a91beea729bc2c13b (diff) | |
| download | rust-823632bbfbb2941cdc3c69130f19b39ea565a7aa.tar.gz rust-823632bbfbb2941cdc3c69130f19b39ea565a7aa.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 'compiler')
| -rw-r--r-- | compiler/rustc_parse/src/parser/diagnostics.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index a9fbd0fa33d..8b87e4d9690 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2939,26 +2939,24 @@ impl<'a> Parser<'a> { } let seq_span = lo.to(self.prev_token.span); let mut err = self.dcx().struct_span_err(comma_span, "unexpected `,` in pattern"); - if let Ok(seq_snippet) = self.span_to_snippet(seq_span) { - err.multipart_suggestion( - format!( - "try adding parentheses to match on a tuple{}", - if let CommaRecoveryMode::LikelyTuple = rt { "" } else { "..." }, - ), - vec![ - (seq_span.shrink_to_lo(), "(".to_string()), - (seq_span.shrink_to_hi(), ")".to_string()), - ], + err.multipart_suggestion( + format!( + "try adding parentheses to match on a tuple{}", + if let CommaRecoveryMode::LikelyTuple = rt { "" } else { "..." }, + ), + vec![ + (seq_span.shrink_to_lo(), "(".to_string()), + (seq_span.shrink_to_hi(), ")".to_string()), + ], + Applicability::MachineApplicable, + ); + if let CommaRecoveryMode::EitherTupleOrPipe = rt { + err.span_suggestion( + comma_span, + "...or a vertical bar to match on alternatives", + " |", Applicability::MachineApplicable, ); - if let CommaRecoveryMode::EitherTupleOrPipe = rt { - err.span_suggestion( - seq_span, - "...or a vertical bar to match on multiple alternatives", - seq_snippet.replace(',', " |"), - Applicability::MachineApplicable, - ); - } } Err(err) } |
