1
Fork 0

Auto merge of #84130 - Aaron1011:fix/none-delim-lookahead, r=petrochenkov

Fix lookahead with None-delimited group

Fixes https://github.com/rust-lang/rust/issues/84162, a regression introduced by https://github.com/rust-lang/rust/pull/82608.
This commit is contained in:
bors 2021-04-14 20:45:23 +00:00
commit 16bf626a31
2 changed files with 46 additions and 8 deletions

View file

@ -930,15 +930,38 @@ impl<'a> Parser<'a> {
} }
let frame = &self.token_cursor.frame; let frame = &self.token_cursor.frame;
match frame.tree_cursor.look_ahead(dist - 1) { if frame.delim != DelimToken::NoDelim {
Some(tree) => match tree { let all_normal = (0..dist).all(|i| {
TokenTree::Token(token) => looker(token), let token = frame.tree_cursor.look_ahead(i);
TokenTree::Delimited(dspan, delim, _) => { !matches!(token, Some(TokenTree::Delimited(_, DelimToken::NoDelim, _)))
looker(&Token::new(token::OpenDelim(*delim), dspan.open)) });
} if all_normal {
}, return match frame.tree_cursor.look_ahead(dist - 1) {
None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)), Some(tree) => match tree {
TokenTree::Token(token) => looker(token),
TokenTree::Delimited(dspan, delim, _) => {
looker(&Token::new(token::OpenDelim(*delim), dspan.open))
}
},
None => looker(&Token::new(token::CloseDelim(frame.delim), frame.span.close)),
};
}
} }
let mut cursor = self.token_cursor.clone();
let mut i = 0;
let mut token = Token::dummy();
while i < dist {
token = cursor.next().0;
if matches!(
token.kind,
token::OpenDelim(token::NoDelim) | token::CloseDelim(token::NoDelim)
) {
continue;
}
i += 1;
}
return looker(&token);
} }
/// Returns whether any of the given keywords are `dist` tokens ahead of the current one. /// Returns whether any of the given keywords are `dist` tokens ahead of the current one.

View file

@ -0,0 +1,15 @@
// check-pass
macro_rules! make_struct {
($name:ident) => {
#[derive(Debug)]
struct Foo {
#[cfg(not(FALSE))]
field: fn($name: bool)
}
}
}
make_struct!(param_name);
fn main() {}