about summary refs log tree commit diff
path: root/compiler/rustc_ast/src/ast_like.rs
AgeCommit message (Collapse)AuthorLines
2022-05-11ast: Introduce some traits to get AST node properties genericallyVadim Petrochenkov-320/+0
And use them to avoid constructing some artificial `Nonterminal` tokens during expansion
2022-03-28Remove `Nonterminal::NtTT`.Nicholas Nethercote-3/+1
It's only needed for macro expansion, not as a general element in the AST. This commit removes it, adds `NtOrTt` for the parser and macro expansion cases, and renames the variants in `NamedMatch` to better match the new type.
2022-01-07expand: Refactor `InvocationCollector` visitor for better code reuseVadim Petrochenkov-2/+37
2021-11-28expand: Turn `ast::Crate` into a first class expansion targetVadim Petrochenkov-2/+2
And stop creating a fake `mod` item for the crate root when expanding a crate.
2021-06-06parser: Ensure that all nonterminals have tokens after parsingVadim Petrochenkov-1/+2
2021-04-11Implement token-based handling of attributes during expansionAaron Hill-7/+95
This PR modifies the macro expansion infrastructure to handle attributes in a fully token-based manner. As a result: * Derives macros no longer lose spans when their input is modified by eager cfg-expansion. This is accomplished by performing eager cfg-expansion on the token stream that we pass to the derive proc-macro * Inner attributes now preserve spans in all cases, including when we have multiple inner attributes in a row. This is accomplished through the following changes: * New structs `AttrAnnotatedTokenStream` and `AttrAnnotatedTokenTree` are introduced. These are very similar to a normal `TokenTree`, but they also track the position of attributes and attribute targets within the stream. They are built when we collect tokens during parsing. An `AttrAnnotatedTokenStream` is converted to a regular `TokenStream` when we invoke a macro. * Token capturing and `LazyTokenStream` are modified to work with `AttrAnnotatedTokenStream`. A new `ReplaceRange` type is introduced, which is created during the parsing of a nested AST node to make the 'outer' AST node aware of the attributes and attribute target stored deeper in the token stream. * When we need to perform eager cfg-expansion (either due to `#[derive]` or `#[cfg_eval]`), we tokenize and reparse our target, capturing additional information about the locations of `#[cfg]` and `#[cfg_attr]` attributes at any depth within the target. This is a performance optimization, allowing us to perform less work in the typical case where captured tokens never have eager cfg-expansion run.
2021-03-16ast/hir: Rename field-related structuresVadim Petrochenkov-3/+2
StructField -> FieldDef ("field definition") Field -> ExprField ("expression field", not "field expression") FieldPat -> PatField ("pattern field", not "field pattern") Also rename visiting and other methods working on them.
2021-03-06rustc_ast: Replace `AstLike::finalize_tokens` with a getter `tokens_mut`Vadim Petrochenkov-54/+34
2021-02-27Combine HasAttrs and HasTokens into AstLikeAaron Hill-0/+219
When token-based attribute handling is implemeneted in #80689, we will need to access tokens from `HasAttrs` (to perform cfg-stripping), and we will to access attributes from `HasTokens` (to construct a `PreexpTokenStream`). This PR merges the `HasAttrs` and `HasTokens` traits into a new `AstLike` trait. The previous `HasAttrs` impls from `Vec<Attribute>` and `AttrVec` are removed - they aren't attribute targets, so the impls never really made sense.