Skip to content

Commit 3f3de5b

Browse files
committed
Fix diagnostics str::replace comma to bar
1 parent f51c987 commit 3f3de5b

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

compiler/rustc_parse/src/parser/diagnostics.rs

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,26 +2929,24 @@ impl<'a> Parser<'a> {
29292929
}
29302930
let seq_span = lo.to(self.prev_token.span);
29312931
let mut err = self.dcx().struct_span_err(comma_span, "unexpected `,` in pattern");
2932-
if let Ok(seq_snippet) = self.span_to_snippet(seq_span) {
2933-
err.multipart_suggestion(
2934-
format!(
2935-
"try adding parentheses to match on a tuple{}",
2936-
if let CommaRecoveryMode::LikelyTuple = rt { "" } else { "..." },
2937-
),
2938-
vec![
2939-
(seq_span.shrink_to_lo(), "(".to_string()),
2940-
(seq_span.shrink_to_hi(), ")".to_string()),
2941-
],
2932+
err.multipart_suggestion(
2933+
format!(
2934+
"try adding parentheses to match on a tuple{}",
2935+
if let CommaRecoveryMode::LikelyTuple = rt { "" } else { "..." },
2936+
),
2937+
vec![
2938+
(seq_span.shrink_to_lo(), "(".to_string()),
2939+
(seq_span.shrink_to_hi(), ")".to_string()),
2940+
],
2941+
Applicability::MachineApplicable,
2942+
);
2943+
if let CommaRecoveryMode::EitherTupleOrPipe = rt {
2944+
err.span_suggestion(
2945+
comma_span,
2946+
"...or a vertical bar to match on alternative",
2947+
" |",
29422948
Applicability::MachineApplicable,
29432949
);
2944-
if let CommaRecoveryMode::EitherTupleOrPipe = rt {
2945-
err.span_suggestion(
2946-
seq_span,
2947-
"...or a vertical bar to match on multiple alternatives",
2948-
seq_snippet.replace(',', " |"),
2949-
Applicability::MachineApplicable,
2950-
);
2951-
}
29522950
}
29532951
Err(err)
29542952
}

0 commit comments

Comments
 (0)