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:
parent
9fa580b117
commit
fb5fec017b
13 changed files with 264 additions and 206 deletions
|
@ -3,7 +3,7 @@ use super::{ForceCollect, Parser, TokenCursor, TrailingToken};
|
|||
use rustc_ast::token::{self, Token, TokenKind};
|
||||
use rustc_ast::tokenstream::{CreateTokenStream, TokenStream, TokenTree, TreeAndSpacing};
|
||||
use rustc_ast::tokenstream::{DelimSpan, LazyTokenStream, Spacing};
|
||||
use rustc_ast::HasTokens;
|
||||
use rustc_ast::AstLike;
|
||||
use rustc_ast::{self as ast};
|
||||
use rustc_errors::PResult;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
@ -59,7 +59,7 @@ impl<'a> Parser<'a> {
|
|||
/// This restriction shouldn't be an issue in practice,
|
||||
/// since this function is used to record the tokens for
|
||||
/// a parsed AST item, which always has matching delimiters.
|
||||
pub fn collect_tokens_trailing_token<R: HasTokens>(
|
||||
pub fn collect_tokens_trailing_token<R: AstLike>(
|
||||
&mut self,
|
||||
attrs: AttrWrapper,
|
||||
force_collect: ForceCollect,
|
||||
|
|
|
@ -22,7 +22,7 @@ use rustc_ast::token::{self, DelimToken, Token, TokenKind};
|
|||
use rustc_ast::tokenstream::{self, DelimSpan, Spacing};
|
||||
use rustc_ast::tokenstream::{TokenStream, TokenTree, TreeAndSpacing};
|
||||
use rustc_ast::DUMMY_NODE_ID;
|
||||
use rustc_ast::{self as ast, AnonConst, AttrStyle, AttrVec, Const, CrateSugar, Extern, HasTokens};
|
||||
use rustc_ast::{self as ast, AnonConst, AstLike, AttrStyle, AttrVec, Const, CrateSugar, Extern};
|
||||
use rustc_ast::{Async, Expr, ExprKind, MacArgs, MacDelimiter, Mutability, StrLit, Unsafe};
|
||||
use rustc_ast::{Visibility, VisibilityKind};
|
||||
use rustc_ast_pretty::pprust;
|
||||
|
@ -1228,7 +1228,7 @@ impl<'a> Parser<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn collect_tokens_no_attrs<R: HasTokens>(
|
||||
pub fn collect_tokens_no_attrs<R: AstLike>(
|
||||
&mut self,
|
||||
f: impl FnOnce(&mut Self) -> PResult<'a, R>,
|
||||
) -> PResult<'a, R> {
|
||||
|
|
|
@ -8,10 +8,10 @@ use super::{AttrWrapper, BlockMode, ForceCollect, Parser, Restrictions, SemiColo
|
|||
use crate::maybe_whole;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::attr::HasAttrs;
|
||||
use rustc_ast::ptr::P;
|
||||
use rustc_ast::token::{self, TokenKind};
|
||||
use rustc_ast::util::classify;
|
||||
use rustc_ast::AstLike;
|
||||
use rustc_ast::{AttrStyle, AttrVec, Attribute, MacCall, MacCallStmt, MacStmtStyle};
|
||||
use rustc_ast::{Block, BlockCheckMode, Expr, ExprKind, Local, Stmt, StmtKind, DUMMY_NODE_ID};
|
||||
use rustc_errors::{Applicability, PResult};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue