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:
Aaron Hill 2021-01-13 16:28:57 -05:00
parent 9bc8b00b4a
commit a961e6785c
No known key found for this signature in database
GPG key ID: B4087E510E98B164
7 changed files with 101 additions and 147 deletions

View file

@ -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)?
};