diff options
Diffstat (limited to 'compiler/rustc_expand')
| -rw-r--r-- | compiler/rustc_expand/src/base.rs | 95 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/build.rs | 218 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/expand.rs | 122 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/module.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/placeholders.rs | 68 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/proc_macro.rs | 3 | ||||
| -rw-r--r-- | compiler/rustc_expand/src/stats.rs | 3 |
7 files changed, 262 insertions, 250 deletions
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 1a9832b2fe2..c234aa43c09 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -7,7 +7,6 @@ use std::rc::Rc; use std::sync::Arc; use rustc_ast::attr::{AttributeExt, MarkedAttrs}; -use rustc_ast::ptr::P; use rustc_ast::token::MetaVarKind; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{AssocCtxt, Visitor}; @@ -45,11 +44,11 @@ use crate::stats::MacroStat; // to use `assign_id!` #[derive(Debug, Clone)] pub enum Annotatable { - Item(P<ast::Item>), - AssocItem(P<ast::AssocItem>, AssocCtxt), - ForeignItem(P<ast::ForeignItem>), - Stmt(P<ast::Stmt>), - Expr(P<ast::Expr>), + Item(Box<ast::Item>), + AssocItem(Box<ast::AssocItem>, AssocCtxt), + ForeignItem(Box<ast::ForeignItem>), + Stmt(Box<ast::Stmt>), + Expr(Box<ast::Expr>), Arm(ast::Arm), ExprField(ast::ExprField), PatField(ast::PatField), @@ -141,28 +140,28 @@ impl Annotatable { } } - pub fn expect_item(self) -> P<ast::Item> { + pub fn expect_item(self) -> Box<ast::Item> { match self { Annotatable::Item(i) => i, _ => panic!("expected Item"), } } - pub fn expect_trait_item(self) -> P<ast::AssocItem> { + pub fn expect_trait_item(self) -> Box<ast::AssocItem> { match self { Annotatable::AssocItem(i, AssocCtxt::Trait) => i, _ => panic!("expected Item"), } } - pub fn expect_impl_item(self) -> P<ast::AssocItem> { + pub fn expect_impl_item(self) -> Box<ast::AssocItem> { match self { Annotatable::AssocItem(i, AssocCtxt::Impl { .. }) => i, _ => panic!("expected Item"), } } - pub fn expect_foreign_item(self) -> P<ast::ForeignItem> { + pub fn expect_foreign_item(self) -> Box<ast::ForeignItem> { match self { Annotatable::ForeignItem(i) => i, _ => panic!("expected foreign item"), @@ -176,7 +175,7 @@ impl Annotatable { } } - pub fn expect_expr(self) -> P<ast::Expr> { + pub fn expect_expr(self) -> Box<ast::Expr> { match self { Annotatable::Expr(expr) => expr, _ => panic!("expected expression"), @@ -412,37 +411,37 @@ macro_rules! make_stmts_default { /// methods are spliced into the AST at the callsite of the macro. pub trait MacResult { /// Creates an expression. - fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> { + fn make_expr(self: Box<Self>) -> Option<Box<ast::Expr>> { None } /// Creates zero or more items. - fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> { + fn make_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::Item>; 1]>> { None } /// Creates zero or more impl items. - fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { None } /// Creates zero or more impl items. - fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { None } /// Creates zero or more trait items. - fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { None } /// Creates zero or more items in an `extern {}` block - fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[P<ast::ForeignItem>; 1]>> { + fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::ForeignItem>; 1]>> { None } /// Creates a pattern. - fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> { + fn make_pat(self: Box<Self>) -> Option<Box<ast::Pat>> { None } @@ -454,7 +453,7 @@ pub trait MacResult { make_stmts_default!(self) } - fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> { + fn make_ty(self: Box<Self>) -> Option<Box<ast::Ty>> { None } @@ -521,38 +520,38 @@ macro_rules! make_MacEager { } make_MacEager! { - expr: P<ast::Expr>, - pat: P<ast::Pat>, - items: SmallVec<[P<ast::Item>; 1]>, - impl_items: SmallVec<[P<ast::AssocItem>; 1]>, - trait_items: SmallVec<[P<ast::AssocItem>; 1]>, - foreign_items: SmallVec<[P<ast::ForeignItem>; 1]>, + expr: Box<ast::Expr>, + pat: Box<ast::Pat>, + items: SmallVec<[Box<ast::Item>; 1]>, + impl_items: SmallVec<[Box<ast::AssocItem>; 1]>, + trait_items: SmallVec<[Box<ast::AssocItem>; 1]>, + foreign_items: SmallVec<[Box<ast::ForeignItem>; 1]>, stmts: SmallVec<[ast::Stmt; 1]>, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, } impl MacResult for MacEager { - fn make_expr(self: Box<Self>) -> Option<P<ast::Expr>> { + fn make_expr(self: Box<Self>) -> Option<Box<ast::Expr>> { self.expr } - fn make_items(self: Box<Self>) -> Option<SmallVec<[P<ast::Item>; 1]>> { + fn make_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::Item>; 1]>> { self.items } - fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { self.impl_items } - fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_impl_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { self.impl_items } - fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { self.trait_items } - fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[P<ast::ForeignItem>; 1]>> { + fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::ForeignItem>; 1]>> { self.foreign_items } @@ -563,13 +562,13 @@ impl MacResult for MacEager { } } - fn make_pat(self: Box<Self>) -> Option<P<ast::Pat>> { + fn make_pat(self: Box<Self>) -> Option<Box<ast::Pat>> { if let Some(p) = self.pat { return Some(p); } if let Some(e) = self.expr { if matches!(e.kind, ast::ExprKind::Lit(_) | ast::ExprKind::IncludedBytes(_)) { - return Some(P(ast::Pat { + return Some(Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, span: e.span, kind: PatKind::Expr(e), @@ -580,7 +579,7 @@ impl MacResult for MacEager { None } - fn make_ty(self: Box<Self>) -> Option<P<ast::Ty>> { + fn make_ty(self: Box<Self>) -> Option<Box<ast::Ty>> { self.ty } } @@ -608,8 +607,8 @@ impl DummyResult { } /// A plain dummy expression. - pub fn raw_expr(sp: Span, guar: Option<ErrorGuaranteed>) -> P<ast::Expr> { - P(ast::Expr { + pub fn raw_expr(sp: Span, guar: Option<ErrorGuaranteed>) -> Box<ast::Expr> { + Box::new(ast::Expr { id: ast::DUMMY_NODE_ID, kind: if let Some(guar) = guar { ast::ExprKind::Err(guar) @@ -624,12 +623,12 @@ impl DummyResult { } impl MacResult for DummyResult { - fn make_expr(self: Box<DummyResult>) -> Option<P<ast::Expr>> { + fn make_expr(self: Box<DummyResult>) -> Option<Box<ast::Expr>> { Some(DummyResult::raw_expr(self.span, self.guar)) } - fn make_pat(self: Box<DummyResult>) -> Option<P<ast::Pat>> { - Some(P(ast::Pat { + fn make_pat(self: Box<DummyResult>) -> Option<Box<ast::Pat>> { + Some(Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind: PatKind::Wild, span: self.span, @@ -637,23 +636,23 @@ impl MacResult for DummyResult { })) } - fn make_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::Item>; 1]>> { + fn make_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::Item>; 1]>> { Some(SmallVec::new()) } - fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { Some(SmallVec::new()) } - fn make_trait_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_impl_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { Some(SmallVec::new()) } - fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[P<ast::AssocItem>; 1]>> { + fn make_trait_items(self: Box<DummyResult>) -> Option<SmallVec<[Box<ast::AssocItem>; 1]>> { Some(SmallVec::new()) } - fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[P<ast::ForeignItem>; 1]>> { + fn make_foreign_items(self: Box<Self>) -> Option<SmallVec<[Box<ast::ForeignItem>; 1]>> { Some(SmallVec::new()) } @@ -665,11 +664,11 @@ impl MacResult for DummyResult { }]) } - fn make_ty(self: Box<DummyResult>) -> Option<P<ast::Ty>> { + fn make_ty(self: Box<DummyResult>) -> Option<Box<ast::Ty>> { // FIXME(nnethercote): you might expect `ast::TyKind::Dummy` to be used here, but some // values produced here end up being lowered to HIR, which `ast::TyKind::Dummy` does not // support, so we use an empty tuple instead. - Some(P(ast::Ty { + Some(Box::new(ast::Ty { id: ast::DUMMY_NODE_ID, kind: ast::TyKind::Tup(ThinVec::new()), span: self.span, @@ -1162,7 +1161,7 @@ pub trait LintStoreExpand { registered_tools: &RegisteredTools, node_id: NodeId, attrs: &[Attribute], - items: &[P<Item>], + items: &[Box<Item>], name: Symbol, ); } diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 51d6e43ab67..c3e86ec0614 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::token::Delimiter; use rustc_ast::tokenstream::TokenStream; use rustc_ast::util::literal; @@ -59,10 +58,10 @@ impl<'a> ExtCtxt<'a> { path: ast::Path, delim: Delimiter, tokens: TokenStream, - ) -> P<ast::MacCall> { - P(ast::MacCall { + ) -> Box<ast::MacCall> { + Box::new(ast::MacCall { path, - args: P(ast::DelimArgs { + args: Box::new(ast::DelimArgs { dspan: tokenstream::DelimSpan { open: span, close: span }, delim, tokens, @@ -70,32 +69,32 @@ impl<'a> ExtCtxt<'a> { }) } - pub fn ty_mt(&self, ty: P<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy { + pub fn ty_mt(&self, ty: Box<ast::Ty>, mutbl: ast::Mutability) -> ast::MutTy { ast::MutTy { ty, mutbl } } - pub fn ty(&self, span: Span, kind: ast::TyKind) -> P<ast::Ty> { - P(ast::Ty { id: ast::DUMMY_NODE_ID, span, kind, tokens: None }) + pub fn ty(&self, span: Span, kind: ast::TyKind) -> Box<ast::Ty> { + Box::new(ast::Ty { id: ast::DUMMY_NODE_ID, span, kind, tokens: None }) } - pub fn ty_infer(&self, span: Span) -> P<ast::Ty> { + pub fn ty_infer(&self, span: Span) -> Box<ast::Ty> { self.ty(span, ast::TyKind::Infer) } - pub fn ty_path(&self, path: ast::Path) -> P<ast::Ty> { + pub fn ty_path(&self, path: ast::Path) -> Box<ast::Ty> { self.ty(path.span, ast::TyKind::Path(None, path)) } // Might need to take bounds as an argument in the future, if you ever want // to generate a bounded existential trait type. - pub fn ty_ident(&self, span: Span, ident: Ident) -> P<ast::Ty> { + pub fn ty_ident(&self, span: Span, ident: Ident) -> Box<ast::Ty> { self.ty_path(self.path_ident(span, ident)) } pub fn anon_const(&self, span: Span, kind: ast::ExprKind) -> ast::AnonConst { ast::AnonConst { id: ast::DUMMY_NODE_ID, - value: P(ast::Expr { + value: Box::new(ast::Expr { id: ast::DUMMY_NODE_ID, kind, span, @@ -112,14 +111,14 @@ impl<'a> ExtCtxt<'a> { pub fn ty_ref( &self, span: Span, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, lifetime: Option<ast::Lifetime>, mutbl: ast::Mutability, - ) -> P<ast::Ty> { + ) -> Box<ast::Ty> { self.ty(span, ast::TyKind::Ref(lifetime, self.ty_mt(ty, mutbl))) } - pub fn ty_ptr(&self, span: Span, ty: P<ast::Ty>, mutbl: ast::Mutability) -> P<ast::Ty> { + pub fn ty_ptr(&self, span: Span, ty: Box<ast::Ty>, mutbl: ast::Mutability) -> Box<ast::Ty> { self.ty(span, ast::TyKind::Ptr(self.ty_mt(ty, mutbl))) } @@ -128,7 +127,7 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, bounds: ast::GenericBounds, - default: Option<P<ast::Ty>>, + default: Option<Box<ast::Ty>>, ) -> ast::GenericParam { ast::GenericParam { ident: ident.with_span_pos(span), @@ -163,7 +162,7 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, bounds: ast::GenericBounds, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, default: Option<AnonConst>, ) -> ast::GenericParam { ast::GenericParam { @@ -211,11 +210,11 @@ impl<'a> ExtCtxt<'a> { self.lifetime(span, Ident::new(kw::StaticLifetime, span)) } - pub fn stmt_expr(&self, expr: P<ast::Expr>) -> ast::Stmt { + pub fn stmt_expr(&self, expr: Box<ast::Expr>) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, span: expr.span, kind: ast::StmtKind::Expr(expr) } } - pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: P<ast::Expr>) -> ast::Stmt { + pub fn stmt_let(&self, sp: Span, mutbl: bool, ident: Ident, ex: Box<ast::Expr>) -> ast::Stmt { self.stmt_let_ty(sp, mutbl, ident, None, ex) } @@ -224,15 +223,15 @@ impl<'a> ExtCtxt<'a> { sp: Span, mutbl: bool, ident: Ident, - ty: Option<P<ast::Ty>>, - ex: P<ast::Expr>, + ty: Option<Box<ast::Ty>>, + ex: Box<ast::Expr>, ) -> ast::Stmt { let pat = if mutbl { self.pat_ident_binding_mode(sp, ident, ast::BindingMode::MUT) } else { self.pat_ident(sp, ident) }; - let local = P(ast::Local { + let local = Box::new(ast::Local { super_: None, pat, ty, @@ -247,8 +246,8 @@ impl<'a> ExtCtxt<'a> { } /// Generates `let _: Type;`, which is usually used for type assertions. - pub fn stmt_let_type_only(&self, span: Span, ty: P<ast::Ty>) -> ast::Stmt { - let local = P(ast::Local { + pub fn stmt_let_type_only(&self, span: Span, ty: Box<ast::Ty>) -> ast::Stmt { + let local = Box::new(ast::Local { super_: None, pat: self.pat_wild(span), ty: Some(ty), @@ -262,19 +261,19 @@ impl<'a> ExtCtxt<'a> { self.stmt_local(local, span) } - pub fn stmt_semi(&self, expr: P<ast::Expr>) -> ast::Stmt { + pub fn stmt_semi(&self, expr: Box<ast::Expr>) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, span: expr.span, kind: ast::StmtKind::Semi(expr) } } - pub fn stmt_local(&self, local: P<ast::Local>, span: Span) -> ast::Stmt { + pub fn stmt_local(&self, local: Box<ast::Local>, span: Span) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Let(local), span } } - pub fn stmt_item(&self, sp: Span, item: P<ast::Item>) -> ast::Stmt { + pub fn stmt_item(&self, sp: Span, item: Box<ast::Item>) -> ast::Stmt { ast::Stmt { id: ast::DUMMY_NODE_ID, kind: ast::StmtKind::Item(item), span: sp } } - pub fn block_expr(&self, expr: P<ast::Expr>) -> P<ast::Block> { + pub fn block_expr(&self, expr: Box<ast::Expr>) -> Box<ast::Block> { self.block( expr.span, thin_vec![ast::Stmt { @@ -284,8 +283,8 @@ impl<'a> ExtCtxt<'a> { }], ) } - pub fn block(&self, span: Span, stmts: ThinVec<ast::Stmt>) -> P<ast::Block> { - P(ast::Block { + pub fn block(&self, span: Span, stmts: ThinVec<ast::Stmt>) -> Box<ast::Block> { + Box::new(ast::Block { stmts, id: ast::DUMMY_NODE_ID, rules: BlockCheckMode::Default, @@ -294,22 +293,28 @@ impl<'a> ExtCtxt<'a> { }) } - pub fn expr(&self, span: Span, kind: ast::ExprKind) -> P<ast::Expr> { - P(ast::Expr { id: ast::DUMMY_NODE_ID, kind, span, attrs: AttrVec::new(), tokens: None }) + pub fn expr(&self, span: Span, kind: ast::ExprKind) -> Box<ast::Expr> { + Box::new(ast::Expr { + id: ast::DUMMY_NODE_ID, + kind, + span, + attrs: AttrVec::new(), + tokens: None, + }) } - pub fn expr_path(&self, path: ast::Path) -> P<ast::Expr> { + pub fn expr_path(&self, path: ast::Path) -> Box<ast::Expr> { self.expr(path.span, ast::ExprKind::Path(None, path)) } - pub fn expr_ident(&self, span: Span, id: Ident) -> P<ast::Expr> { + pub fn expr_ident(&self, span: Span, id: Ident) -> Box<ast::Expr> { self.expr_path(self.path_ident(span, id)) } - pub fn expr_self(&self, span: Span) -> P<ast::Expr> { + pub fn expr_self(&self, span: Span) -> Box<ast::Expr> { self.expr_ident(span, Ident::with_dummy_span(kw::SelfLower)) } - pub fn expr_macro_call(&self, span: Span, call: P<ast::MacCall>) -> P<ast::Expr> { + pub fn expr_macro_call(&self, span: Span, call: Box<ast::MacCall>) -> Box<ast::Expr> { self.expr(span, ast::ExprKind::MacCall(call)) } @@ -317,31 +322,31 @@ impl<'a> ExtCtxt<'a> { &self, sp: Span, op: ast::BinOpKind, - lhs: P<ast::Expr>, - rhs: P<ast::Expr>, - ) -> P<ast::Expr> { + lhs: Box<ast::Expr>, + rhs: Box<ast::Expr>, + ) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Binary(Spanned { node: op, span: sp }, lhs, rhs)) } - pub fn expr_deref(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_deref(&self, sp: Span, e: Box<ast::Expr>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Unary(UnOp::Deref, e)) } - pub fn expr_addr_of(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_addr_of(&self, sp: Span, e: Box<ast::Expr>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::AddrOf(ast::BorrowKind::Ref, ast::Mutability::Not, e)) } - pub fn expr_paren(&self, sp: Span, e: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_paren(&self, sp: Span, e: Box<ast::Expr>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Paren(e)) } pub fn expr_method_call( &self, span: Span, - expr: P<ast::Expr>, + expr: Box<ast::Expr>, ident: Ident, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { let seg = ast::PathSegment::from_ident(ident); self.expr( span, @@ -357,38 +362,38 @@ impl<'a> ExtCtxt<'a> { pub fn expr_call( &self, span: Span, - expr: P<ast::Expr>, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + expr: Box<ast::Expr>, + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { self.expr(span, ast::ExprKind::Call(expr, args)) } - pub fn expr_loop(&self, sp: Span, block: P<ast::Block>) -> P<ast::Expr> { + pub fn expr_loop(&self, sp: Span, block: Box<ast::Block>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Loop(block, None, sp)) } - pub fn expr_asm(&self, sp: Span, expr: P<ast::InlineAsm>) -> P<ast::Expr> { + pub fn expr_asm(&self, sp: Span, expr: Box<ast::InlineAsm>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::InlineAsm(expr)) } pub fn expr_call_ident( &self, span: Span, id: Ident, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { self.expr(span, ast::ExprKind::Call(self.expr_ident(span, id), args)) } pub fn expr_call_global( &self, sp: Span, fn_path: Vec<Ident>, - args: ThinVec<P<ast::Expr>>, - ) -> P<ast::Expr> { + args: ThinVec<Box<ast::Expr>>, + ) -> Box<ast::Expr> { let pathexpr = self.expr_path(self.path_global(sp, fn_path)); self.expr_call(sp, pathexpr, args) } - pub fn expr_block(&self, b: P<ast::Block>) -> P<ast::Expr> { + pub fn expr_block(&self, b: Box<ast::Block>) -> Box<ast::Expr> { self.expr(b.span, ast::ExprKind::Block(b, None)) } - pub fn field_imm(&self, span: Span, ident: Ident, e: P<ast::Expr>) -> ast::ExprField { + pub fn field_imm(&self, span: Span, ident: Ident, e: Box<ast::Expr>) -> ast::ExprField { ast::ExprField { ident: ident.with_span_pos(span), expr: e, @@ -404,10 +409,10 @@ impl<'a> ExtCtxt<'a> { span: Span, path: ast::Path, fields: ThinVec<ast::ExprField>, - ) -> P<ast::Expr> { + ) -> Box<ast::Expr> { self.expr( span, - ast::ExprKind::Struct(P(ast::StructExpr { + ast::ExprKind::Struct(Box::new(ast::StructExpr { qself: None, path, fields, @@ -420,61 +425,61 @@ impl<'a> ExtCtxt<'a> { span: Span, id: Ident, fields: ThinVec<ast::ExprField>, - ) -> P<ast::Expr> { + ) -> Box<ast::Expr> { self.expr_struct(span, self.path_ident(span, id), fields) } - pub fn expr_usize(&self, span: Span, n: usize) -> P<ast::Expr> { + pub fn expr_usize(&self, span: Span, n: usize) -> Box<ast::Expr> { let suffix = Some(ast::UintTy::Usize.name()); let lit = token::Lit::new(token::Integer, sym::integer(n), suffix); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_u32(&self, span: Span, n: u32) -> P<ast::Expr> { + pub fn expr_u32(&self, span: Span, n: u32) -> Box<ast::Expr> { let suffix = Some(ast::UintTy::U32.name()); let lit = token::Lit::new(token::Integer, sym::integer(n), suffix); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_bool(&self, span: Span, value: bool) -> P<ast::Expr> { + pub fn expr_bool(&self, span: Span, value: bool) -> Box<ast::Expr> { let lit = token::Lit::new(token::Bool, if value { kw::True } else { kw::False }, None); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_str(&self, span: Span, s: Symbol) -> P<ast::Expr> { + pub fn expr_str(&self, span: Span, s: Symbol) -> Box<ast::Expr> { let lit = token::Lit::new(token::Str, literal::escape_string_symbol(s), None); self.expr(span, ast::ExprKind::Lit(lit)) } - pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> P<ast::Expr> { + pub fn expr_byte_str(&self, span: Span, bytes: Vec<u8>) -> Box<ast::Expr> { let lit = token::Lit::new(token::ByteStr, literal::escape_byte_str_symbol(&bytes), None); self.expr(span, ast::ExprKind::Lit(lit)) } /// `[expr1, expr2, ...]` - pub fn expr_array(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_array(&self, sp: Span, exprs: ThinVec<Box<ast::Expr>>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Array(exprs)) } /// `&[expr1, expr2, ...]` - pub fn expr_array_ref(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_array_ref(&self, sp: Span, exprs: ThinVec<Box<ast::Expr>>) -> Box<ast::Expr> { self.expr_addr_of(sp, self.expr_array(sp, exprs)) } - pub fn expr_some(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_some(&self, sp: Span, expr: Box<ast::Expr>) -> Box<ast::Expr> { let some = self.std_path(&[sym::option, sym::Option, sym::Some]); self.expr_call_global(sp, some, thin_vec![expr]) } - pub fn expr_none(&self, sp: Span) -> P<ast::Expr> { + pub fn expr_none(&self, sp: Span) -> Box<ast::Expr> { let none = self.std_path(&[sym::option, sym::Option, sym::None]); self.expr_path(self.path_global(sp, none)) } - pub fn expr_tuple(&self, sp: Span, exprs: ThinVec<P<ast::Expr>>) -> P<ast::Expr> { + pub fn expr_tuple(&self, sp: Span, exprs: ThinVec<Box<ast::Expr>>) -> Box<ast::Expr> { self.expr(sp, ast::ExprKind::Tup(exprs)) } - pub fn expr_unreachable(&self, span: Span) -> P<ast::Expr> { + pub fn expr_unreachable(&self, span: Span) -> Box<ast::Expr> { self.expr_macro_call( span, self.macro_call( @@ -489,12 +494,12 @@ impl<'a> ExtCtxt<'a> { ) } - pub fn expr_ok(&self, sp: Span, expr: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_ok(&self, sp: Span, expr: Box<ast::Expr>) -> Box<ast::Expr> { let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); self.expr_call_global(sp, ok, thin_vec![expr]) } - pub fn expr_try(&self, sp: Span, head: P<ast::Expr>) -> P<ast::Expr> { + pub fn expr_try(&self, sp: Span, head: Box<ast::Expr>) -> Box<ast::Expr> { let ok = self.std_path(&[sym::result, sym::Result, sym::Ok]); let ok_path = self.path_global(sp, ok); let err = self.std_path(&[sym::result, sym::Result, sym::Err]); @@ -523,16 +528,16 @@ impl<'a> ExtCtxt<'a> { self.expr_match(sp, head, thin_vec![ok_arm, err_arm]) } - pub fn pat(&self, span: Span, kind: PatKind) -> P<ast::Pat> { - P(ast::Pat { id: ast::DUMMY_NODE_ID, kind, span, tokens: None }) + pub fn pat(&self, span: Span, kind: PatKind) -> Box<ast::Pat> { + Box::new(ast::Pat { id: ast::DUMMY_NODE_ID, kind, span, tokens: None }) } - pub fn pat_wild(&self, span: Span) -> P<ast::Pat> { + pub fn pat_wild(&self, span: Span) -> Box<ast::Pat> { self.pat(span, PatKind::Wild) } - pub fn pat_lit(&self, span: Span, expr: P<ast::Expr>) -> P<ast::Pat> { + pub fn pat_lit(&self, span: Span, expr: Box<ast::Expr>) -> Box<ast::Pat> { self.pat(span, PatKind::Expr(expr)) } - pub fn pat_ident(&self, span: Span, ident: Ident) -> P<ast::Pat> { + pub fn pat_ident(&self, span: Span, ident: Ident) -> Box<ast::Pat> { self.pat_ident_binding_mode(span, ident, ast::BindingMode::NONE) } @@ -541,19 +546,19 @@ impl<'a> ExtCtxt<'a> { span: Span, ident: Ident, ann: ast::BindingMode, - ) -> P<ast::Pat> { + ) -> Box<ast::Pat> { let pat = PatKind::Ident(ann, ident.with_span_pos(span), None); self.pat(span, pat) } - pub fn pat_path(&self, span: Span, path: ast::Path) -> P<ast::Pat> { + pub fn pat_path(&self, span: Span, path: ast::Path) -> Box<ast::Pat> { self.pat(span, PatKind::Path(None, path)) } pub fn pat_tuple_struct( &self, span: Span, path: ast::Path, - subpats: ThinVec<P<ast::Pat>>, - ) -> P<ast::Pat> { + subpats: ThinVec<Box<ast::Pat>>, + ) -> Box<ast::Pat> { self.pat(span, PatKind::TupleStruct(None, path, subpats)) } pub fn pat_struct( @@ -561,20 +566,20 @@ impl<'a> ExtCtxt<'a> { span: Span, path: ast::Path, field_pats: ThinVec<ast::PatField>, - ) -> P<ast::Pat> { + ) -> Box<ast::Pat> { self.pat(span, PatKind::Struct(None, path, field_pats, ast::PatFieldsRest::None)) } - pub fn pat_tuple(&self, span: Span, pats: ThinVec<P<ast::Pat>>) -> P<ast::Pat> { + pub fn pat_tuple(&self, span: Span, pats: ThinVec<Box<ast::Pat>>) -> Box<ast::Pat> { self.pat(span, PatKind::Tuple(pats)) } - pub fn pat_some(&self, span: Span, pat: P<ast::Pat>) -> P<ast::Pat> { + pub fn pat_some(&self, span: Span, pat: Box<ast::Pat>) -> Box<ast::Pat> { let some = self.std_path(&[sym::option, sym::Option, sym::Some]); let path = self.path_global(span, some); self.pat_tuple_struct(span, path, thin_vec![pat]) } - pub fn arm(&self, span: Span, pat: P<ast::Pat>, expr: P<ast::Expr>) -> ast::Arm { + pub fn arm(&self, span: Span, pat: Box<ast::Pat>, expr: Box<ast::Expr>) -> ast::Arm { ast::Arm { attrs: AttrVec::new(), pat, @@ -590,22 +595,27 @@ impl<'a> ExtCtxt<'a> { self.arm(span, self.pat_wild(span), self.expr_unreachable(span)) } - pub fn expr_match(&self, span: Span, arg: P<ast::Expr>, arms: ThinVec<ast::Arm>) -> P<Expr> { + pub fn expr_match( + &self, + span: Span, + arg: Box<ast::Expr>, + arms: ThinVec<ast::Arm>, + ) -> Box<Expr> { self.expr(span, ast::ExprKind::Match(arg, arms, MatchKind::Prefix)) } pub fn expr_if( &self, span: Span, - cond: P<ast::Expr>, - then: P<ast::Expr>, - els: Option<P<ast::Expr>>, - ) -> P<ast::Expr> { + cond: Box<ast::Expr>, + then: Box<ast::Expr>, + els: Option<Box<ast::Expr>>, + ) -> Box<ast::Expr> { let els = els.map(|x| self.expr_block(self.block_expr(x))); self.expr(span, ast::ExprKind::If(cond, self.block_expr(then), els)) } - pub fn lambda(&self, span: Span, ids: Vec<Ident>, body: P<ast::Expr>) -> P<ast::Expr> { + pub fn lambda(&self, span: Span, ids: Vec<Ident>, body: Box<ast::Expr>) -> Box<ast::Expr> { let fn_decl = self.fn_decl( ids.iter().map(|id| self.param(span, *id, self.ty(span, ast::TyKind::Infer))).collect(), ast::FnRetTy::Default(span), @@ -633,11 +643,11 @@ impl<'a> ExtCtxt<'a> { ) } - pub fn lambda0(&self, span: Span, body: P<ast::Expr>) -> P<ast::Expr> { + pub fn lambda0(&self, span: Span, body: Box<ast::Expr>) -> Box<ast::Expr> { self.lambda(span, Vec::new(), body) } - pub fn lambda1(&self, span: Span, body: P<ast::Expr>, ident: Ident) -> P<ast::Expr> { + pub fn lambda1(&self, span: Span, body: Box<ast::Expr>, ident: Ident) -> Box<ast::Expr> { self.lambda(span, vec![ident], body) } @@ -646,11 +656,11 @@ impl<'a> ExtCtxt<'a> { span: Span, stmts: ThinVec<ast::Stmt>, ident: Ident, - ) -> P<ast::Expr> { + ) -> Box<ast::Expr> { self.lambda1(span, self.expr_block(self.block(span, stmts)), ident) } - pub fn param(&self, span: Span, ident: Ident, ty: P<ast::Ty>) -> ast::Param { + pub fn param(&self, span: Span, ident: Ident, ty: Box<ast::Ty>) -> ast::Param { let arg_pat = self.pat_ident(span, ident); ast::Param { attrs: AttrVec::default(), @@ -663,12 +673,12 @@ impl<'a> ExtCtxt<'a> { } // `self` is unused but keep it as method for the convenience use. - pub fn fn_decl(&self, inputs: ThinVec<ast::Param>, output: ast::FnRetTy) -> P<ast::FnDecl> { - P(ast::FnDecl { inputs, output }) + pub fn fn_decl(&self, inputs: ThinVec<ast::Param>, output: ast::FnRetTy) -> Box<ast::FnDecl> { + Box::new(ast::FnDecl { inputs, output }) } - pub fn item(&self, span: Span, attrs: ast::AttrVec, kind: ast::ItemKind) -> P<ast::Item> { - P(ast::Item { + pub fn item(&self, span: Span, attrs: ast::AttrVec, kind: ast::ItemKind) -> Box<ast::Item> { + Box::new(ast::Item { attrs, id: ast::DUMMY_NODE_ID, kind, @@ -686,10 +696,10 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, ident: Ident, - ty: P<ast::Ty>, + ty: Box<ast::Ty>, mutability: ast::Mutability, - expr: P<ast::Expr>, - ) -> P<ast::Item> { + expr: Box<ast::Expr>, + ) -> Box<ast::Item> { self.item( span, AttrVec::new(), @@ -711,9 +721,9 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, ident: Ident, - ty: P<ast::Ty>, - expr: P<ast::Expr>, - ) -> P<ast::Item> { + ty: Box<ast::Ty>, + expr: Box<ast::Expr>, + ) -> Box<ast::Item> { let defaultness = ast::Defaultness::Final; self.item( span, diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index f02aa6c120f..e7ae4416968 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -4,7 +4,6 @@ use std::sync::Arc; use std::{iter, mem}; use rustc_ast::mut_visit::*; -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_ast::visit::{self, AssocCtxt, Visitor, VisitorResult, try_visit, walk_list}; use rustc_ast::{ @@ -65,8 +64,8 @@ macro_rules! ast_fragments { /// A fragment of AST that can be produced by a single macro expansion. /// Can also serve as an input and intermediate result for macro expansion operations. pub enum AstFragment { - OptExpr(Option<P<ast::Expr>>), - MethodReceiverExpr(P<ast::Expr>), + OptExpr(Option<Box<ast::Expr>>), + MethodReceiverExpr(Box<ast::Expr>), $($Kind($AstTy),)* } @@ -112,14 +111,14 @@ macro_rules! ast_fragments { } } - pub(crate) fn make_opt_expr(self) -> Option<P<ast::Expr>> { + pub(crate) fn make_opt_expr(self) -> Option<Box<ast::Expr>> { match self { AstFragment::OptExpr(expr) => expr, _ => panic!("AstFragment::make_* called on the wrong kind of fragment"), } } - pub(crate) fn make_method_receiver_expr(self) -> P<ast::Expr> { + pub(crate) fn make_method_receiver_expr(self) -> Box<ast::Expr> { match self { AstFragment::MethodReceiverExpr(expr) => expr, _ => panic!("AstFragment::make_* called on the wrong kind of fragment"), @@ -188,17 +187,17 @@ macro_rules! ast_fragments { } ast_fragments! { - Expr(P<ast::Expr>) { + Expr(Box<ast::Expr>) { "expression"; one fn visit_expr; fn visit_expr; fn pprust::expr_to_string; fn make_expr; } - Pat(P<ast::Pat>) { + Pat(Box<ast::Pat>) { "pattern"; one fn visit_pat; fn visit_pat; fn pprust::pat_to_string; fn make_pat; } - Ty(P<ast::Ty>) { + Ty(Box<ast::Ty>) { "type"; one fn visit_ty; fn visit_ty; fn pprust::ty_to_string; fn make_ty; @@ -208,30 +207,30 @@ ast_fragments! { many fn flat_map_stmt; fn visit_stmt(); fn pprust::stmt_to_string; fn make_stmts; } - Items(SmallVec<[P<ast::Item>; 1]>) { + Items(SmallVec<[Box<ast::Item>; 1]>) { "item"; many fn flat_map_item; fn visit_item(); fn pprust::item_to_string; fn make_items; } - TraitItems(SmallVec<[P<ast::AssocItem>; 1]>) { + TraitItems(SmallVec<[Box<ast::AssocItem>; 1]>) { "trait item"; many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Trait); fn pprust::assoc_item_to_string; fn make_trait_items; } - ImplItems(SmallVec<[P<ast::AssocItem>; 1]>) { + ImplItems(SmallVec<[Box<ast::AssocItem>; 1]>) { "impl item"; many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Impl { of_trait: false }); fn pprust::assoc_item_to_string; fn make_impl_items; } - TraitImplItems(SmallVec<[P<ast::AssocItem>; 1]>) { + TraitImplItems(SmallVec<[Box<ast::AssocItem>; 1]>) { "impl item"; many fn flat_map_assoc_item; fn visit_assoc_item(AssocCtxt::Impl { of_trait: true }); fn pprust::assoc_item_to_string; fn make_trait_impl_items; } - ForeignItems(SmallVec<[P<ast::ForeignItem>; 1]>) { + ForeignItems(SmallVec<[Box<ast::ForeignItem>; 1]>) { "foreign item"; many fn flat_map_foreign_item; fn visit_foreign_item(); fn pprust::foreign_item_to_string; fn make_foreign_items; @@ -392,7 +391,7 @@ pub struct Invocation { pub enum InvocationKind { Bang { - mac: P<ast::MacCall>, + mac: Box<ast::MacCall>, span: Span, }, Attr { @@ -409,7 +408,7 @@ pub enum InvocationKind { item: Annotatable, }, GlobDelegation { - item: P<ast::AssocItem>, + item: Box<ast::AssocItem>, /// Whether this is a trait impl or an inherent impl of_trait: bool, }, @@ -948,15 +947,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> { _ => unreachable!(), }; - type Node = AstNodeWrapper<P<ast::AssocItem>, ImplItemTag>; + type Node = AstNodeWrapper<Box<ast::AssocItem>, ImplItemTag>; let single_delegations = build_single_delegations::<Node>( self.cx, deleg, &item, &suffixes, item.span, true, ); // `-Zmacro-stats` ignores these because they don't seem important. - fragment_kind.expect_from_annotatables( - single_delegations - .map(|item| Annotatable::AssocItem(P(item), AssocCtxt::Impl { of_trait })), - ) + fragment_kind.expect_from_annotatables(single_delegations.map(|item| { + Annotatable::AssocItem(Box::new(item), AssocCtxt::Impl { of_trait }) + })) } }) } @@ -1228,7 +1226,7 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { fn is_mac_call(&self) -> bool { false } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { unreachable!() } fn delegation(&self) -> Option<(&ast::DelegationMac, &ast::Item<Self::ItemKind>)> { @@ -1269,7 +1267,7 @@ trait InvocationCollectorNode: HasAttrs + HasNodeId + Sized { } } -impl InvocationCollectorNode for P<ast::Item> { +impl InvocationCollectorNode for Box<ast::Item> { const KIND: AstFragmentKind = AstFragmentKind::Items; fn to_annotatable(self) -> Annotatable { Annotatable::Item(self) @@ -1283,7 +1281,7 @@ impl InvocationCollectorNode for P<ast::Item> { fn is_mac_call(&self) -> bool { matches!(self.kind, ItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { ItemKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1299,7 +1297,7 @@ impl InvocationCollectorNode for P<ast::Item> { ItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - P(item) + Box::new(item) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1421,8 +1419,8 @@ impl InvocationCollectorNode for P<ast::Item> { } struct TraitItemTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> { - type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::AssocItem>, TraitItemTag> { + type OutputTy = SmallVec<[Box<ast::AssocItem>; 1]>; type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::TraitItems; fn to_annotatable(self) -> Annotatable { @@ -1437,7 +1435,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), @@ -1454,7 +1452,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> AssocItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - AstNodeWrapper::new(P(item), TraitItemTag) + AstNodeWrapper::new(Box::new(item), TraitItemTag) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1462,8 +1460,8 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitItemTag> } struct ImplItemTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> { - type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::AssocItem>, ImplItemTag> { + type OutputTy = SmallVec<[Box<ast::AssocItem>; 1]>; type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::ImplItems; fn to_annotatable(self) -> Annotatable { @@ -1478,7 +1476,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), @@ -1495,7 +1493,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> AssocItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - AstNodeWrapper::new(P(item), ImplItemTag) + AstNodeWrapper::new(Box::new(item), ImplItemTag) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1503,8 +1501,8 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, ImplItemTag> } struct TraitImplItemTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitImplItemTag> { - type OutputTy = SmallVec<[P<ast::AssocItem>; 1]>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::AssocItem>, TraitImplItemTag> { + type OutputTy = SmallVec<[Box<ast::AssocItem>; 1]>; type ItemKind = AssocItemKind; const KIND: AstFragmentKind = AstFragmentKind::TraitImplItems; fn to_annotatable(self) -> Annotatable { @@ -1519,7 +1517,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitImplItem fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), @@ -1536,14 +1534,14 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::AssocItem>, TraitImplItem AssocItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - AstNodeWrapper::new(P(item), TraitImplItemTag) + AstNodeWrapper::new(Box::new(item), TraitImplItemTag) } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() } } -impl InvocationCollectorNode for P<ast::ForeignItem> { +impl InvocationCollectorNode for Box<ast::ForeignItem> { const KIND: AstFragmentKind = AstFragmentKind::ForeignItems; fn to_annotatable(self) -> Annotatable { Annotatable::ForeignItem(self) @@ -1557,7 +1555,7 @@ impl InvocationCollectorNode for P<ast::ForeignItem> { fn is_mac_call(&self) -> bool { matches!(self.kind, ForeignItemKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { ForeignItemKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1672,7 +1670,7 @@ impl InvocationCollectorNode for ast::Arm { impl InvocationCollectorNode for ast::Stmt { const KIND: AstFragmentKind = AstFragmentKind::Stmts; fn to_annotatable(self) -> Annotatable { - Annotatable::Stmt(P(self)) + Annotatable::Stmt(Box::new(self)) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_stmts() @@ -1689,7 +1687,7 @@ impl InvocationCollectorNode for ast::Stmt { StmtKind::Let(..) | StmtKind::Empty => false, } } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { // We pull macro invocations (both attributes and fn-like macro calls) out of their // `StmtKind`s and treat them as statement macro invocations, not as items or expressions. let (add_semicolon, mac, attrs) = match self.kind { @@ -1726,7 +1724,7 @@ impl InvocationCollectorNode for ast::Stmt { ItemKind::Delegation(deleg) } fn from_item(item: ast::Item<Self::ItemKind>) -> Self { - ast::Stmt { id: ast::DUMMY_NODE_ID, span: item.span, kind: StmtKind::Item(P(item)) } + ast::Stmt { id: ast::DUMMY_NODE_ID, span: item.span, kind: StmtKind::Item(Box::new(item)) } } fn flatten_outputs(items: impl Iterator<Item = Self::OutputTy>) -> Self::OutputTy { items.flatten().collect() @@ -1769,7 +1767,7 @@ impl InvocationCollectorNode for ast::Crate { } impl InvocationCollectorNode for ast::Ty { - type OutputTy = P<ast::Ty>; + type OutputTy = Box<ast::Ty>; const KIND: AstFragmentKind = AstFragmentKind::Ty; fn to_annotatable(self) -> Annotatable { unreachable!() @@ -1793,7 +1791,7 @@ impl InvocationCollectorNode for ast::Ty { fn is_mac_call(&self) -> bool { matches!(self.kind, ast::TyKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { TyKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No), _ => unreachable!(), @@ -1802,7 +1800,7 @@ impl InvocationCollectorNode for ast::Ty { } impl InvocationCollectorNode for ast::Pat { - type OutputTy = P<ast::Pat>; + type OutputTy = Box<ast::Pat>; const KIND: AstFragmentKind = AstFragmentKind::Pat; fn to_annotatable(self) -> Annotatable { unreachable!() @@ -1816,7 +1814,7 @@ impl InvocationCollectorNode for ast::Pat { fn is_mac_call(&self) -> bool { matches!(self.kind, PatKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { PatKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No), _ => unreachable!(), @@ -1825,10 +1823,10 @@ impl InvocationCollectorNode for ast::Pat { } impl InvocationCollectorNode for ast::Expr { - type OutputTy = P<ast::Expr>; + type OutputTy = Box<ast::Expr>; const KIND: AstFragmentKind = AstFragmentKind::Expr; fn to_annotatable(self) -> Annotatable { - Annotatable::Expr(P(self)) + Annotatable::Expr(Box::new(self)) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { fragment.make_expr() @@ -1842,7 +1840,7 @@ impl InvocationCollectorNode for ast::Expr { fn is_mac_call(&self) -> bool { matches!(self.kind, ExprKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { match self.kind { ExprKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1851,8 +1849,8 @@ impl InvocationCollectorNode for ast::Expr { } struct OptExprTag; -impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> { - type OutputTy = Option<P<ast::Expr>>; +impl InvocationCollectorNode for AstNodeWrapper<Box<ast::Expr>, OptExprTag> { + type OutputTy = Option<Box<ast::Expr>>; const KIND: AstFragmentKind = AstFragmentKind::OptExpr; fn to_annotatable(self) -> Annotatable { Annotatable::Expr(self.wrapped) @@ -1867,7 +1865,7 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> { fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let node = self.wrapped; match node.kind { ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), @@ -1884,13 +1882,13 @@ impl InvocationCollectorNode for AstNodeWrapper<P<ast::Expr>, OptExprTag> { struct MethodReceiverTag; impl InvocationCollectorNode for AstNodeWrapper<ast::Expr, MethodReceiverTag> { - type OutputTy = AstNodeWrapper<P<ast::Expr>, MethodReceiverTag>; + type OutputTy = AstNodeWrapper<Box<ast::Expr>, MethodReceiverTag>; const KIND: AstFragmentKind = AstFragmentKind::MethodReceiverExpr; fn descr() -> &'static str { "an expression" } fn to_annotatable(self) -> Annotatable { - Annotatable::Expr(P(self.wrapped)) + Annotatable::Expr(Box::new(self.wrapped)) } fn fragment_to_output(fragment: AstFragment) -> Self::OutputTy { AstNodeWrapper::new(fragment.make_method_receiver_expr(), MethodReceiverTag) @@ -1901,7 +1899,7 @@ impl InvocationCollectorNode for AstNodeWrapper<ast::Expr, MethodReceiverTag> { fn is_mac_call(&self) -> bool { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) } - fn take_mac_call(self) -> (P<ast::MacCall>, ast::AttrVec, AddSemicolon) { + fn take_mac_call(self) -> (Box<ast::MacCall>, ast::AttrVec, AddSemicolon) { let node = self.wrapped; match node.kind { ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), @@ -2038,7 +2036,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { placeholder(fragment_kind, NodeId::placeholder_from_expn_id(expn_id), vis) } - fn collect_bang(&mut self, mac: P<ast::MacCall>, kind: AstFragmentKind) -> AstFragment { + fn collect_bang(&mut self, mac: Box<ast::MacCall>, kind: AstFragmentKind) -> AstFragment { // cache the macro call span so that it can be // easily adjusted for incremental compilation let span = mac.span(); @@ -2056,7 +2054,7 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { fn collect_glob_delegation( &mut self, - item: P<ast::AssocItem>, + item: Box<ast::AssocItem>, of_trait: bool, kind: AstFragmentKind, ) -> AstFragment { @@ -2328,15 +2326,15 @@ impl<'a, 'b> InvocationCollector<'a, 'b> { } impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { - fn flat_map_item(&mut self, node: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { + fn flat_map_item(&mut self, node: Box<ast::Item>) -> SmallVec<[Box<ast::Item>; 1]> { self.flat_map_node(node) } fn flat_map_assoc_item( &mut self, - node: P<ast::AssocItem>, + node: Box<ast::AssocItem>, ctxt: AssocCtxt, - ) -> SmallVec<[P<ast::AssocItem>; 1]> { + ) -> SmallVec<[Box<ast::AssocItem>; 1]> { match ctxt { AssocCtxt::Trait => self.flat_map_node(AstNodeWrapper::new(node, TraitItemTag)), AssocCtxt::Impl { of_trait: false } => { @@ -2350,8 +2348,8 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { fn flat_map_foreign_item( &mut self, - node: P<ast::ForeignItem>, - ) -> SmallVec<[P<ast::ForeignItem>; 1]> { + node: Box<ast::ForeignItem>, + ) -> SmallVec<[Box<ast::ForeignItem>; 1]> { self.flat_map_node(node) } @@ -2446,7 +2444,7 @@ impl<'a, 'b> MutVisitor for InvocationCollector<'a, 'b> { self.visit_node(AstNodeWrapper::from_mut(node, MethodReceiverTag)) } - fn filter_map_expr(&mut self, node: P<ast::Expr>) -> Option<P<ast::Expr>> { + fn filter_map_expr(&mut self, node: Box<ast::Expr>) -> Option<Box<ast::Expr>> { self.flat_map_node(AstNodeWrapper::new(node, OptExprTag)) } diff --git a/compiler/rustc_expand/src/module.rs b/compiler/rustc_expand/src/module.rs index e925052c607..662c67f2d3f 100644 --- a/compiler/rustc_expand/src/module.rs +++ b/compiler/rustc_expand/src/module.rs @@ -1,7 +1,6 @@ use std::iter::once; use std::path::{self, Path, PathBuf}; -use rustc_ast::ptr::P; use rustc_ast::{AttrVec, Attribute, Inline, Item, ModSpans}; use rustc_errors::{Diag, ErrorGuaranteed}; use rustc_parse::{exp, new_parser_from_file, unwrap_or_emit_fatal, validate_attr}; @@ -31,7 +30,7 @@ pub struct ModulePathSuccess { } pub(crate) struct ParsedExternalMod { - pub items: ThinVec<P<Item>>, + pub items: ThinVec<Box<Item>>, pub spans: ModSpans, pub file_path: PathBuf, pub dir_path: PathBuf, diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 6e1c6df4bcb..05f9a5aa43f 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -1,5 +1,4 @@ use rustc_ast::mut_visit::*; -use rustc_ast::ptr::P; use rustc_ast::token::Delimiter; use rustc_ast::visit::AssocCtxt; use rustc_ast::{self as ast, Safety}; @@ -15,10 +14,10 @@ pub(crate) fn placeholder( id: ast::NodeId, vis: Option<ast::Visibility>, ) -> AstFragment { - fn mac_placeholder() -> P<ast::MacCall> { - P(ast::MacCall { + fn mac_placeholder() -> Box<ast::MacCall> { + Box::new(ast::MacCall { path: ast::Path { span: DUMMY_SP, segments: ThinVec::new(), tokens: None }, - args: P(ast::DelimArgs { + args: Box::new(ast::DelimArgs { dspan: ast::tokenstream::DelimSpan::dummy(), delim: Delimiter::Parenthesis, tokens: ast::tokenstream::TokenStream::new(Vec::new()), @@ -35,7 +34,7 @@ pub(crate) fn placeholder( }); let span = DUMMY_SP; let expr_placeholder = || { - P(ast::Expr { + Box::new(ast::Expr { id, span, attrs: ast::AttrVec::new(), @@ -43,10 +42,17 @@ pub(crate) fn placeholder( tokens: None, }) }; - let ty = - || P(ast::Ty { id, kind: ast::TyKind::MacCall(mac_placeholder()), span, tokens: None }); - let pat = - || P(ast::Pat { id, kind: ast::PatKind::MacCall(mac_placeholder()), span, tokens: None }); + let ty = || { + Box::new(ast::Ty { id, kind: ast::TyKind::MacCall(mac_placeholder()), span, tokens: None }) + }; + let pat = || { + Box::new(ast::Pat { + id, + kind: ast::PatKind::MacCall(mac_placeholder()), + span, + tokens: None, + }) + }; match kind { AstFragmentKind::Crate => AstFragment::Crate(ast::Crate { @@ -59,7 +65,7 @@ pub(crate) fn placeholder( AstFragmentKind::Expr => AstFragment::Expr(expr_placeholder()), AstFragmentKind::OptExpr => AstFragment::OptExpr(Some(expr_placeholder())), AstFragmentKind::MethodReceiverExpr => AstFragment::MethodReceiverExpr(expr_placeholder()), - AstFragmentKind::Items => AstFragment::Items(smallvec![P(ast::Item { + AstFragmentKind::Items => AstFragment::Items(smallvec![Box::new(ast::Item { id, span, vis, @@ -67,15 +73,17 @@ pub(crate) fn placeholder( kind: ast::ItemKind::MacCall(mac_placeholder()), tokens: None, })]), - AstFragmentKind::TraitItems => AstFragment::TraitItems(smallvec![P(ast::AssocItem { - id, - span, - vis, - attrs, - kind: ast::AssocItemKind::MacCall(mac_placeholder()), - tokens: None, - })]), - AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![P(ast::AssocItem { + AstFragmentKind::TraitItems => { + AstFragment::TraitItems(smallvec![Box::new(ast::AssocItem { + id, + span, + vis, + attrs, + kind: ast::AssocItemKind::MacCall(mac_placeholder()), + tokens: None, + })]) + } + AstFragmentKind::ImplItems => AstFragment::ImplItems(smallvec![Box::new(ast::AssocItem { id, span, vis, @@ -84,7 +92,7 @@ pub(crate) fn placeholder( tokens: None, })]), AstFragmentKind::TraitImplItems => { - AstFragment::TraitImplItems(smallvec![P(ast::AssocItem { + AstFragment::TraitImplItems(smallvec![Box::new(ast::AssocItem { id, span, vis, @@ -94,7 +102,7 @@ pub(crate) fn placeholder( })]) } AstFragmentKind::ForeignItems => { - AstFragment::ForeignItems(smallvec![P(ast::ForeignItem { + AstFragment::ForeignItems(smallvec![Box::new(ast::ForeignItem { id, span, vis, @@ -103,20 +111,20 @@ pub(crate) fn placeholder( tokens: None, })]) } - AstFragmentKind::Pat => AstFragment::Pat(P(ast::Pat { + AstFragmentKind::Pat => AstFragment::Pat(Box::new(ast::Pat { id, span, kind: ast::PatKind::MacCall(mac_placeholder()), tokens: None, })), - AstFragmentKind::Ty => AstFragment::Ty(P(ast::Ty { + AstFragmentKind::Ty => AstFragment::Ty(Box::new(ast::Ty { id, span, kind: ast::TyKind::MacCall(mac_placeholder()), tokens: None, })), AstFragmentKind::Stmts => AstFragment::Stmts(smallvec![{ - let mac = P(ast::MacCallStmt { + let mac = Box::new(ast::MacCallStmt { mac: mac_placeholder(), style: ast::MacStmtStyle::Braces, attrs: ast::AttrVec::new(), @@ -297,7 +305,7 @@ impl MutVisitor for PlaceholderExpander { } } - fn flat_map_item(&mut self, item: P<ast::Item>) -> SmallVec<[P<ast::Item>; 1]> { + fn flat_map_item(&mut self, item: Box<ast::Item>) -> SmallVec<[Box<ast::Item>; 1]> { match item.kind { ast::ItemKind::MacCall(_) => self.remove(item.id).make_items(), _ => walk_flat_map_item(self, item), @@ -306,9 +314,9 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_assoc_item( &mut self, - item: P<ast::AssocItem>, + item: Box<ast::AssocItem>, ctxt: AssocCtxt, - ) -> SmallVec<[P<ast::AssocItem>; 1]> { + ) -> SmallVec<[Box<ast::AssocItem>; 1]> { match item.kind { ast::AssocItemKind::MacCall(_) => { let it = self.remove(item.id); @@ -324,8 +332,8 @@ impl MutVisitor for PlaceholderExpander { fn flat_map_foreign_item( &mut self, - item: P<ast::ForeignItem>, - ) -> SmallVec<[P<ast::ForeignItem>; 1]> { + item: Box<ast::ForeignItem>, + ) -> SmallVec<[Box<ast::ForeignItem>; 1]> { match item.kind { ast::ForeignItemKind::MacCall(_) => self.remove(item.id).make_foreign_items(), _ => walk_flat_map_foreign_item(self, item), @@ -346,7 +354,7 @@ impl MutVisitor for PlaceholderExpander { } } - fn filter_map_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> { + fn filter_map_expr(&mut self, expr: Box<ast::Expr>) -> Option<Box<ast::Expr>> { match expr.kind { ast::ExprKind::MacCall(_) => self.remove(expr.id).make_opt_expr(), _ => walk_filter_map_expr(self, expr), diff --git a/compiler/rustc_expand/src/proc_macro.rs b/compiler/rustc_expand/src/proc_macro.rs index 84fbbbef061..9bfda8764f5 100644 --- a/compiler/rustc_expand/src/proc_macro.rs +++ b/compiler/rustc_expand/src/proc_macro.rs @@ -1,4 +1,3 @@ -use rustc_ast::ptr::P; use rustc_ast::tokenstream::TokenStream; use rustc_errors::ErrorGuaranteed; use rustc_parse::parser::{ForceCollect, Parser}; @@ -161,7 +160,7 @@ impl MultiItemModifier for DeriveProcMacro { Ok(None) => break, Ok(Some(item)) => { if is_stmt { - items.push(Annotatable::Stmt(P(ecx.stmt_item(span, item)))); + items.push(Annotatable::Stmt(Box::new(ecx.stmt_item(span, item)))); } else { items.push(Annotatable::Item(item)); } diff --git a/compiler/rustc_expand/src/stats.rs b/compiler/rustc_expand/src/stats.rs index b4c4eac028f..3e40632275b 100644 --- a/compiler/rustc_expand/src/stats.rs +++ b/compiler/rustc_expand/src/stats.rs @@ -1,6 +1,5 @@ use std::iter; -use rustc_ast::ptr::P; use rustc_ast::{self as ast, DUMMY_NODE_ID, Expr, ExprKind}; use rustc_ast_pretty::pprust; use rustc_span::hygiene::{ExpnKind, MacroKind}; @@ -41,7 +40,7 @@ pub(crate) fn update_bang_macro_stats( ecx: &mut ExtCtxt<'_>, fragment_kind: AstFragmentKind, span: Span, - mac: P<ast::MacCall>, + mac: Box<ast::MacCall>, fragment: &AstFragment, ) { // Does this path match any of the include macros, e.g. `include!`? |
