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:
commit
16bf626a31
@ -930,15 +930,38 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
|
||||
let frame = &self.token_cursor.frame;
|
||||
match frame.tree_cursor.look_ahead(dist - 1) {
|
||||
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)),
|
||||
if frame.delim != DelimToken::NoDelim {
|
||||
let all_normal = (0..dist).all(|i| {
|
||||
let token = frame.tree_cursor.look_ahead(i);
|
||||
!matches!(token, Some(TokenTree::Delimited(_, DelimToken::NoDelim, _)))
|
||||
});
|
||||
if all_normal {
|
||||
return match frame.tree_cursor.look_ahead(dist - 1) {
|
||||
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.
|
||||
|
15
src/test/ui/macros/none-delim-lookahead.rs
Normal file
15
src/test/ui/macros/none-delim-lookahead.rs
Normal 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() {}
|
Loading…
x
Reference in New Issue
Block a user