Rollup merge of #113999 - Centri3:macro-arm-expand, r=wesleywiser
Specify macro is invalid in certain contexts Adds a note when a macro is used where it really shouldn't be. Closes #113766
This commit is contained in:
commit
1f076fe1d8
9 changed files with 246 additions and 24 deletions
|
@ -2641,6 +2641,7 @@ impl<'a> Parser<'a> {
|
|||
pub(crate) fn maybe_recover_unexpected_comma(
|
||||
&mut self,
|
||||
lo: Span,
|
||||
is_mac_invoc: bool,
|
||||
rt: CommaRecoveryMode,
|
||||
) -> PResult<'a, ()> {
|
||||
if self.token != token::Comma {
|
||||
|
@ -2661,24 +2662,28 @@ impl<'a> Parser<'a> {
|
|||
let seq_span = lo.to(self.prev_token.span);
|
||||
let mut err = self.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()),
|
||||
],
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
if let CommaRecoveryMode::EitherTupleOrPipe = rt {
|
||||
err.span_suggestion(
|
||||
seq_span,
|
||||
"...or a vertical bar to match on multiple alternatives",
|
||||
seq_snippet.replace(',', " |"),
|
||||
if is_mac_invoc {
|
||||
err.note(fluent::parse_macro_expands_to_match_arm);
|
||||
} else {
|
||||
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(
|
||||
seq_span,
|
||||
"...or a vertical bar to match on multiple alternatives",
|
||||
seq_snippet.replace(',', " |"),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue