1
Fork 0

Combine HasAttrs and HasTokens into AstLike

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.
This commit is contained in:
Aaron Hill 2021-02-23 10:21:20 -05:00
parent 9fa580b117
commit fb5fec017b
No known key found for this signature in database
GPG key ID: B4087E510E98B164
13 changed files with 264 additions and 206 deletions

View file

@ -12,11 +12,11 @@ use rustc_ast::ptr::P;
use rustc_ast::token;
use rustc_ast::tokenstream::TokenStream;
use rustc_ast::visit::{self, AssocCtxt, Visitor};
use rustc_ast::{AttrItem, AttrStyle, Block, Inline, ItemKind, LitKind, MacArgs};
use rustc_ast::{AstLike, AttrItem, AttrStyle, Block, Inline, ItemKind, LitKind, MacArgs};
use rustc_ast::{MacCallStmt, MacStmtStyle, MetaItemKind, ModKind, NestedMetaItem};
use rustc_ast::{NodeId, PatKind, Path, StmtKind, Unsafe};
use rustc_ast_pretty::pprust;
use rustc_attr::{self as attr, is_builtin_attr, HasAttrs};
use rustc_attr::{self as attr, is_builtin_attr};
use rustc_data_structures::map_in_place::MapInPlace;
use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_data_structures::sync::Lrc;
@ -1014,7 +1014,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
/// legacy derive helpers (helpers written before derives that introduce them).
fn take_first_attr(
&mut self,
item: &mut impl HasAttrs,
item: &mut impl AstLike,
) -> Option<(ast::Attribute, usize, Vec<Path>)> {
let mut attr = None;
@ -1045,7 +1045,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
attr
}
fn configure<T: HasAttrs>(&mut self, node: T) -> Option<T> {
fn configure<T: AstLike>(&mut self, node: T) -> Option<T> {
self.cfg.configure(node)
}