Set tokens on AST node in collect_tokens
A new `HasTokens` trait is introduced, which is used to move logic from the callers of `collect_tokens` into the body of `collect_tokens`. In addition to reducing duplication, this paves the way for PR #80689, which needs to perform additional logic during token collection.
This commit is contained in:
parent
9bc8b00b4a
commit
a961e6785c
7 changed files with 101 additions and 147 deletions
|
@ -89,15 +89,7 @@ impl<'a> Parser<'a> {
|
|||
};
|
||||
|
||||
let stmt = if has_attrs {
|
||||
let (mut stmt, tokens) = self.collect_tokens(parse_stmt_inner)?;
|
||||
if let Some(stmt) = &mut stmt {
|
||||
// If we already have tokens (e.g. due to encounting an `NtStmt`),
|
||||
// use those instead.
|
||||
if stmt.tokens().is_none() {
|
||||
stmt.set_tokens(tokens);
|
||||
}
|
||||
}
|
||||
stmt
|
||||
self.collect_tokens(parse_stmt_inner)?
|
||||
} else {
|
||||
parse_stmt_inner(self)?
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue