Skip to content

Commit 4735c21

Browse files
A4-Tackskarolzwolak
authored andcommitted
Fix diagnostics str::replace comma to bar
1 parent d4ae855 commit 4735c21

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
@@ -2947,26 +2947,24 @@ impl<'a> Parser<'a> {
29472947
}
29482948
let seq_span = lo.to(self.prev_token.span);
29492949
let mut err = self.dcx().struct_span_err(comma_span, "unexpected `,` in pattern");
2950-
if let Ok(seq_snippet) = self.span_to_snippet(seq_span) {
2951-
err.multipart_suggestion(
2952-
format!(
2953-
"try adding parentheses to match on a tuple{}",
2954-
if let CommaRecoveryMode::LikelyTuple = rt { "" } else { "..." },
2955-
),
2956-
vec![
2957-
(seq_span.shrink_to_lo(), "(".to_string()),
2958-
(seq_span.shrink_to_hi(), ")".to_string()),
2959-
],
2950+
err.multipart_suggestion(
2951+
format!(
2952+
"try adding parentheses to match on a tuple{}",
2953+
if let CommaRecoveryMode::LikelyTuple = rt { "" } else { "..." },
2954+
),
2955+
vec![
2956+
(seq_span.shrink_to_lo(), "(".to_string()),
2957+
(seq_span.shrink_to_hi(), ")".to_string()),
2958+
],
2959+
Applicability::MachineApplicable,
2960+
);
2961+
if let CommaRecoveryMode::EitherTupleOrPipe = rt {
2962+
err.span_suggestion(
2963+
comma_span,
2964+
"...or a vertical bar to match on alternative",
2965+
" |",
29602966
Applicability::MachineApplicable,
29612967
);
2962-
if let CommaRecoveryMode::EitherTupleOrPipe = rt {
2963-
err.span_suggestion(
2964-
seq_span,
2965-
"...or a vertical bar to match on multiple alternatives",
2966-
seq_snippet.replace(',', " |"),
2967-
Applicability::MachineApplicable,
2968-
);
2969-
}
29702968
}
29712969
Err(err)
29722970
}

0 commit comments

Comments
 (0)