Skip to content

Commit

Permalink
Fix lookahead with None-delimited group
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron1011 committed Apr 12, 2021
1 parent c18c0ad commit eb7b1a1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
22 changes: 13 additions & 9 deletions compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -929,16 +929,20 @@ impl<'a> Parser<'a> {
return looker(&self.token);
}

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)),
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.
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/macros/none-delim-lookahead.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit eb7b1a1

Please sign in to comment.