diff options
| author | Aaron Hill <aa1ronham@gmail.com> | 2021-01-22 13:28:08 -0500 |
|---|---|---|
| committer | Aaron Hill <aa1ronham@gmail.com> | 2021-02-13 12:07:15 -0500 |
| commit | 0b411f56e1a539e2388e9a983feb45f362923dc5 (patch) | |
| tree | a630893ab6e51faada2847b807e38afb28949270 /compiler/rustc_ast/src | |
| parent | 7e0241c63755ea28045d512b742f50b307874419 (diff) | |
| download | rust-0b411f56e1a539e2388e9a983feb45f362923dc5.tar.gz rust-0b411f56e1a539e2388e9a983feb45f362923dc5.zip | |
Require passing an `AttrWrapper` to `collect_tokens_trailing_token`
This is a pure refactoring split out from #80689. It represents the most invasive part of that PR, requiring changes in every caller of `parse_outer_attributes` In order to eagerly expand `#[cfg]` attributes while preserving the original `TokenStream`, we need to know the range of tokens that corresponds to every attribute target. This is accomplished by making `parse_outer_attributes` return an opaque `AttrWrapper` struct. An `AttrWrapper` must be converted to a plain `AttrVec` by passing it to `collect_tokens_trailing_token`. This makes it difficult to accidentally construct an AST node with attributes without calling `collect_tokens_trailing_token`, since AST nodes store an `AttrVec`, not an `AttrWrapper`. As a result, we now call `collect_tokens_trailing_token` for attribute targets which only support inert attributes, such as generic arguments and struct fields. Currently, the constructed `LazyTokenStream` is simply discarded. Future PRs will record the token range corresponding to the attribute target, allowing those tokens to be removed from an enclosing `collect_tokens_trailing_token` call if necessary.
Diffstat (limited to 'compiler/rustc_ast/src')
| -rw-r--r-- | compiler/rustc_ast/src/ast.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 2ddcb9ef844..cd0ad2b0150 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2975,3 +2975,18 @@ macro_rules! derive_has_tokens { derive_has_tokens! { Item, Expr, Ty, AttrItem, Visibility, Path, Block, Pat } + +macro_rules! derive_has_attrs_no_tokens { + ($($ty:path),*) => { $( + impl HasTokens for $ty { + fn finalize_tokens(&mut self, _tokens: LazyTokenStream) {} + } + )* } +} + +// These ast nodes only support inert attributes, so they don't +// store tokens (since nothing can observe them) +derive_has_attrs_no_tokens! { + StructField, Arm, + Field, FieldPat, Variant, Param, GenericParam +} |
