Skip to content

Commit 4523466

Browse files
committed
expand: Import more AST enums
1 parent 800ba8f commit 4523466

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

compiler/rustc_expand/src/expand.rs

+35-35
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ use rustc_ast::ptr::P;
1111
use rustc_ast::token;
1212
use rustc_ast::tokenstream::TokenStream;
1313
use rustc_ast::visit::{self, AssocCtxt, Visitor};
14-
use rustc_ast::{AstLike, AstLikeWrapper, Block, Inline, ItemKind, MacArgs, MacCall};
15-
use rustc_ast::{MacCallStmt, MacStmtStyle, MetaItemKind, ModKind, NestedMetaItem};
16-
use rustc_ast::{NodeId, Path, StmtKind};
14+
use rustc_ast::{AssocItemKind, AstLike, AstLikeWrapper, AttrStyle, ExprKind, ForeignItemKind};
15+
use rustc_ast::{Inline, ItemKind, MacArgs, MacStmtStyle, MetaItemKind, ModKind, NestedMetaItem};
16+
use rustc_ast::{NodeId, PatKind, StmtKind, TyKind};
1717
use rustc_ast_pretty::pprust;
1818
use rustc_attr::is_builtin_attr;
1919
use rustc_data_structures::map_in_place::MapInPlace;
@@ -317,10 +317,10 @@ pub enum InvocationKind {
317317
pos: usize,
318318
item: Annotatable,
319319
// Required for resolving derive helper attributes.
320-
derives: Vec<Path>,
320+
derives: Vec<ast::Path>,
321321
},
322322
Derive {
323-
path: Path,
323+
path: ast::Path,
324324
item: Annotatable,
325325
},
326326
}
@@ -678,7 +678,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
678678
krate,
679679
),
680680
Annotatable::Item(item_inner)
681-
if matches!(attr.style, ast::AttrStyle::Inner)
681+
if matches!(attr.style, AttrStyle::Inner)
682682
&& matches!(
683683
item_inner.kind,
684684
ItemKind::Mod(
@@ -746,7 +746,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
746746
if let SyntaxExtensionKind::Derive(..) = ext {
747747
self.gate_proc_macro_input(&item);
748748
}
749-
let meta = ast::MetaItem { kind: ast::MetaItemKind::Word, span, path };
749+
let meta = ast::MetaItem { kind: MetaItemKind::Word, span, path };
750750
let items = match expander.expand(self.cx, span, &meta, item) {
751751
ExpandResult::Ready(items) => items,
752752
ExpandResult::Retry(item) => {
@@ -808,7 +808,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
808808
impl<'ast, 'a> Visitor<'ast> for GateProcMacroInput<'a> {
809809
fn visit_item(&mut self, item: &'ast ast::Item) {
810810
match &item.kind {
811-
ast::ItemKind::Mod(_, mod_kind)
811+
ItemKind::Mod(_, mod_kind)
812812
if !matches!(mod_kind, ModKind::Loaded(_, Inline::Yes, _)) =>
813813
{
814814
feature_err(
@@ -836,7 +836,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
836836
&mut self,
837837
toks: TokenStream,
838838
kind: AstFragmentKind,
839-
path: &Path,
839+
path: &ast::Path,
840840
span: Span,
841841
) -> AstFragment {
842842
let mut parser = self.cx.new_parser_from_tts(toks);
@@ -928,7 +928,7 @@ pub fn parse_ast_fragment<'a>(
928928

929929
pub fn ensure_complete_parse<'a>(
930930
this: &mut Parser<'a>,
931-
macro_path: &Path,
931+
macro_path: &ast::Path,
932932
kind_name: &str,
933933
span: Span,
934934
) {
@@ -1053,12 +1053,12 @@ impl InvocationCollectorNode for P<ast::Item> {
10531053
noop_flat_map_item(self, visitor)
10541054
}
10551055
fn is_mac_call(&self) -> bool {
1056-
matches!(self.kind, ast::ItemKind::MacCall(..))
1056+
matches!(self.kind, ItemKind::MacCall(..))
10571057
}
10581058
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
10591059
let node = self.into_inner();
10601060
match node.kind {
1061-
ast::ItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
1061+
ItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
10621062
_ => unreachable!(),
10631063
}
10641064
}
@@ -1067,13 +1067,13 @@ impl InvocationCollectorNode for P<ast::Item> {
10671067
collector: &mut InvocationCollector<'_, '_>,
10681068
noop_flat_map: impl FnOnce(Self, &mut InvocationCollector<'_, '_>) -> Self::OutputTy,
10691069
) -> Result<Self::OutputTy, Self> {
1070-
if !matches!(node.kind, ast::ItemKind::Mod(..)) {
1070+
if !matches!(node.kind, ItemKind::Mod(..)) {
10711071
return Ok(noop_flat_map(node, collector));
10721072
}
10731073

10741074
// Work around borrow checker not seeing through `P`'s deref.
10751075
let (ident, span, mut attrs) = (node.ident, node.span, mem::take(&mut node.attrs));
1076-
let ast::ItemKind::Mod(_, mod_kind) = &mut node.kind else {
1076+
let ItemKind::Mod(_, mod_kind) = &mut node.kind else {
10771077
unreachable!()
10781078
};
10791079

@@ -1157,12 +1157,12 @@ impl InvocationCollectorNode for AstLikeWrapper<P<ast::AssocItem>, TraitItemTag>
11571157
noop_flat_map_assoc_item(self.wrapped, visitor)
11581158
}
11591159
fn is_mac_call(&self) -> bool {
1160-
matches!(self.wrapped.kind, ast::AssocItemKind::MacCall(..))
1160+
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
11611161
}
11621162
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
11631163
let item = self.wrapped.into_inner();
11641164
match item.kind {
1165-
ast::AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
1165+
AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
11661166
_ => unreachable!(),
11671167
}
11681168
}
@@ -1185,12 +1185,12 @@ impl InvocationCollectorNode for AstLikeWrapper<P<ast::AssocItem>, ImplItemTag>
11851185
noop_flat_map_assoc_item(self.wrapped, visitor)
11861186
}
11871187
fn is_mac_call(&self) -> bool {
1188-
matches!(self.wrapped.kind, ast::AssocItemKind::MacCall(..))
1188+
matches!(self.wrapped.kind, AssocItemKind::MacCall(..))
11891189
}
11901190
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
11911191
let item = self.wrapped.into_inner();
11921192
match item.kind {
1193-
ast::AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
1193+
AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No),
11941194
_ => unreachable!(),
11951195
}
11961196
}
@@ -1211,12 +1211,12 @@ impl InvocationCollectorNode for P<ast::ForeignItem> {
12111211
noop_flat_map_foreign_item(self, visitor)
12121212
}
12131213
fn is_mac_call(&self) -> bool {
1214-
matches!(self.kind, ast::ForeignItemKind::MacCall(..))
1214+
matches!(self.kind, ForeignItemKind::MacCall(..))
12151215
}
12161216
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
12171217
let node = self.into_inner();
12181218
match node.kind {
1219-
ast::ForeignItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
1219+
ForeignItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
12201220
_ => unreachable!(),
12211221
}
12221222
}
@@ -1353,7 +1353,7 @@ impl InvocationCollectorNode for ast::Stmt {
13531353
match &self.kind {
13541354
StmtKind::MacCall(..) => true,
13551355
StmtKind::Item(item) => matches!(item.kind, ItemKind::MacCall(..)),
1356-
StmtKind::Semi(expr) => matches!(expr.kind, ast::ExprKind::MacCall(..)),
1356+
StmtKind::Semi(expr) => matches!(expr.kind, ExprKind::MacCall(..)),
13571357
StmtKind::Expr(..) => unreachable!(),
13581358
StmtKind::Local(..) | StmtKind::Empty => false,
13591359
}
@@ -1363,7 +1363,7 @@ impl InvocationCollectorNode for ast::Stmt {
13631363
// `StmtKind`s and treat them as statement macro invocations, not as items or expressions.
13641364
let (add_semicolon, mac, attrs) = match self.kind {
13651365
StmtKind::MacCall(mac) => {
1366-
let MacCallStmt { mac, style, attrs, .. } = mac.into_inner();
1366+
let ast::MacCallStmt { mac, style, attrs, .. } = mac.into_inner();
13671367
(style == MacStmtStyle::Semicolon, mac, attrs)
13681368
}
13691369
StmtKind::Item(item) => match item.into_inner() {
@@ -1373,7 +1373,7 @@ impl InvocationCollectorNode for ast::Stmt {
13731373
_ => unreachable!(),
13741374
},
13751375
StmtKind::Semi(expr) => match expr.into_inner() {
1376-
ast::Expr { kind: ast::ExprKind::MacCall(mac), attrs, .. } => {
1376+
ast::Expr { kind: ExprKind::MacCall(mac), attrs, .. } => {
13771377
(mac.args.need_semicolon(), mac, attrs)
13781378
}
13791379
_ => unreachable!(),
@@ -1431,7 +1431,7 @@ impl InvocationCollectorNode for P<ast::Ty> {
14311431
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
14321432
let node = self.into_inner();
14331433
match node.kind {
1434-
ast::TyKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
1434+
TyKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
14351435
_ => unreachable!(),
14361436
}
14371437
}
@@ -1453,12 +1453,12 @@ impl InvocationCollectorNode for P<ast::Pat> {
14531453
noop_visit_pat(self, visitor)
14541454
}
14551455
fn is_mac_call(&self) -> bool {
1456-
matches!(self.kind, ast::PatKind::MacCall(..))
1456+
matches!(self.kind, PatKind::MacCall(..))
14571457
}
14581458
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
14591459
let node = self.into_inner();
14601460
match node.kind {
1461-
ast::PatKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
1461+
PatKind::MacCall(mac) => (mac, Vec::new(), AddSemicolon::No),
14621462
_ => unreachable!(),
14631463
}
14641464
}
@@ -1481,12 +1481,12 @@ impl InvocationCollectorNode for P<ast::Expr> {
14811481
noop_visit_expr(self, visitor)
14821482
}
14831483
fn is_mac_call(&self) -> bool {
1484-
matches!(self.kind, ast::ExprKind::MacCall(..))
1484+
matches!(self.kind, ExprKind::MacCall(..))
14851485
}
14861486
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
14871487
let node = self.into_inner();
14881488
match node.kind {
1489-
ast::ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
1489+
ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
14901490
_ => unreachable!(),
14911491
}
14921492
}
@@ -1516,7 +1516,7 @@ impl InvocationCollectorNode for AstLikeWrapper<P<ast::Expr>, OptExprTag> {
15161516
fn take_mac_call(self) -> (ast::MacCall, Self::AttrsTy, AddSemicolon) {
15171517
let node = self.wrapped.into_inner();
15181518
match node.kind {
1519-
ast::ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
1519+
ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No),
15201520
_ => unreachable!(),
15211521
}
15221522
}
@@ -1560,7 +1560,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
15601560

15611561
fn collect_attr(
15621562
&mut self,
1563-
(attr, pos, derives): (ast::Attribute, usize, Vec<Path>),
1563+
(attr, pos, derives): (ast::Attribute, usize, Vec<ast::Path>),
15641564
item: Annotatable,
15651565
kind: AstFragmentKind,
15661566
) -> AstFragment {
@@ -1573,7 +1573,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
15731573
fn take_first_attr(
15741574
&self,
15751575
item: &mut impl AstLike,
1576-
) -> Option<(ast::Attribute, usize, Vec<Path>)> {
1576+
) -> Option<(ast::Attribute, usize, Vec<ast::Path>)> {
15771577
let mut attr = None;
15781578

15791579
item.visit_attrs(|attrs| {
@@ -1609,7 +1609,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> {
16091609

16101610
// Detect use of feature-gated or invalid attributes on macro invocations
16111611
// since they will not be detected after macro expansion.
1612-
fn check_attributes(&self, attrs: &[ast::Attribute], call: &MacCall) {
1612+
fn check_attributes(&self, attrs: &[ast::Attribute], call: &ast::MacCall) {
16131613
let features = self.cx.ecfg.features.unwrap();
16141614
let mut attrs = attrs.iter().peekable();
16151615
let mut span: Option<Span> = None;
@@ -1764,7 +1764,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
17641764
let mut node = configure!(self, node);
17651765
return match &node.kind {
17661766
StmtKind::Expr(expr)
1767-
if matches!(**expr, ast::Expr { kind: ast::ExprKind::MacCall(..), .. }) =>
1767+
if matches!(**expr, ast::Expr { kind: ExprKind::MacCall(..), .. }) =>
17681768
{
17691769
self.cx.current_expansion.is_trailing_mac = true;
17701770
// Don't use `assign_id` for this statement - it may get removed
@@ -1801,7 +1801,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
18011801
self.flat_map_node(AstLikeWrapper::new(node, OptExprTag))
18021802
}
18031803

1804-
fn visit_block(&mut self, node: &mut P<Block>) {
1804+
fn visit_block(&mut self, node: &mut P<ast::Block>) {
18051805
let orig_dir_ownership = mem::replace(
18061806
&mut self.cx.current_expansion.dir_ownership,
18071807
DirOwnership::UnownedViaBlock,
@@ -1810,7 +1810,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> {
18101810
self.cx.current_expansion.dir_ownership = orig_dir_ownership;
18111811
}
18121812

1813-
fn visit_id(&mut self, id: &mut ast::NodeId) {
1813+
fn visit_id(&mut self, id: &mut NodeId) {
18141814
// We may have already assigned a `NodeId`
18151815
// by calling `assign_id`
18161816
if self.monotonic && *id == ast::DUMMY_NODE_ID {

0 commit comments

Comments
 (0)