rustc_ast: Replace AstLike::finalize_tokens with a getter tokens_mut

This commit is contained in:
Vadim Petrochenkov 2021-03-06 21:06:01 +03:00
parent 51748a8fc7
commit 069e612e73
5 changed files with 60 additions and 78 deletions

View file

@ -72,6 +72,10 @@ impl<'a> Parser<'a> {
let cursor_snapshot = self.token_cursor.clone();
let (mut ret, trailing_token) = f(self, attrs.attrs)?;
let tokens = match ret.tokens_mut() {
Some(tokens) if tokens.is_none() => tokens,
_ => return Ok(ret),
};
// Produces a `TokenStream` on-demand. Using `cursor_snapshot`
// and `num_calls`, we can reconstruct the `TokenStream` seen
@ -128,14 +132,14 @@ impl<'a> Parser<'a> {
}
}
let lazy_impl = LazyTokenStreamImpl {
*tokens = Some(LazyTokenStream::new(LazyTokenStreamImpl {
start_token,
num_calls,
cursor_snapshot,
desugar_doc_comments: self.desugar_doc_comments,
append_unglued_token: self.token_cursor.append_unglued_token.clone(),
};
ret.finalize_tokens(LazyTokenStream::new(lazy_impl));
}));
Ok(ret)
}
}