diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 8f260e1cdb5c8..4eb69fda36514 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -144,9 +144,13 @@ pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec { let close_token = Token::new(token::CloseDelim(delimited.delim), span.close); locs.push(MatcherLoc::Delimited); - locs.push(MatcherLoc::Token { token: open_token }); + if delimited.delim != token::DelimToken::NoDelim { + locs.push(MatcherLoc::Token { token: open_token }); + } inner(&delimited.tts, locs, next_metavar, seq_depth); - locs.push(MatcherLoc::Token { token: close_token }); + if delimited.delim != token::DelimToken::NoDelim { + locs.push(MatcherLoc::Token { token: close_token }); + } } TokenTree::Sequence(_, seq) => { // We can't determine `idx_first_after` and construct the final