Skip to content

Commit c7640aa

Browse files
committed
Auto merge of #31583 - petrochenkov:indi_ast, r=Manishearth
cc #31487 plugin-[breaking-change] The AST part of #30087 r? @Manishearth
2 parents 9257e89 + 77cc576 commit c7640aa

File tree

23 files changed

+271
-254
lines changed

23 files changed

+271
-254
lines changed

src/librustc_driver/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ impl fold::Folder for ReplaceBodyWithLoop {
614614
}
615615
}
616616

617-
fn fold_trait_item(&mut self, i: P<ast::TraitItem>) -> SmallVector<P<ast::TraitItem>> {
617+
fn fold_trait_item(&mut self, i: ast::TraitItem) -> SmallVector<ast::TraitItem> {
618618
match i.node {
619619
ast::TraitItemKind::Const(..) => {
620620
self.within_static_or_const = true;
@@ -626,7 +626,7 @@ impl fold::Folder for ReplaceBodyWithLoop {
626626
}
627627
}
628628

629-
fn fold_impl_item(&mut self, i: P<ast::ImplItem>) -> SmallVector<P<ast::ImplItem>> {
629+
fn fold_impl_item(&mut self, i: ast::ImplItem) -> SmallVector<ast::ImplItem> {
630630
match i.node {
631631
ast::ImplItemKind::Const(..) => {
632632
self.within_static_or_const = true;

src/librustc_trans/save/dump_csv.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
561561
type_parameters: &ast::Generics,
562562
trait_ref: &Option<ast::TraitRef>,
563563
typ: &ast::Ty,
564-
impl_items: &[P<ast::ImplItem>]) {
564+
impl_items: &[ast::ImplItem]) {
565565
let mut has_self_ref = false;
566566
if let Some(impl_data) = self.save_ctxt.get_item_data(item) {
567567
down_cast_data!(impl_data, ImplData, self, item.span);
@@ -602,7 +602,7 @@ impl <'l, 'tcx> DumpCsvVisitor<'l, 'tcx> {
602602
item: &ast::Item,
603603
generics: &ast::Generics,
604604
trait_refs: &ast::TyParamBounds,
605-
methods: &[P<ast::TraitItem>]) {
605+
methods: &[ast::TraitItem]) {
606606
let qualname = format!("::{}", self.tcx.map.path_to_string(item.id));
607607
let val = self.span.snippet(item.span);
608608
let sub_span = self.span.sub_span_after_keyword(item.span, keywords::Trait);

src/libsyntax/ast.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ impl PathParameters {
287287
}
288288
}
289289

290-
pub fn bindings(&self) -> Vec<&P<TypeBinding>> {
290+
pub fn bindings(&self) -> Vec<&TypeBinding> {
291291
match *self {
292292
PathParameters::AngleBracketed(ref data) => {
293293
data.bindings.iter().collect()
@@ -308,7 +308,7 @@ pub struct AngleBracketedParameterData {
308308
pub types: P<[P<Ty>]>,
309309
/// Bindings (equality constraints) on associated types, if present.
310310
/// e.g., `Foo<A=Bar>`.
311-
pub bindings: P<[P<TypeBinding>]>,
311+
pub bindings: P<[TypeBinding]>,
312312
}
313313

314314
impl AngleBracketedParameterData {
@@ -508,7 +508,7 @@ impl PartialEq for MetaItemKind {
508508
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
509509
pub struct Block {
510510
/// Statements in a block
511-
pub stmts: Vec<P<Stmt>>,
511+
pub stmts: Vec<Stmt>,
512512
/// An expression at the end of the block
513513
/// without a semicolon, if any
514514
pub expr: Option<P<Expr>>,
@@ -1716,12 +1716,12 @@ pub struct Mod {
17161716
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17171717
pub struct ForeignMod {
17181718
pub abi: Abi,
1719-
pub items: Vec<P<ForeignItem>>,
1719+
pub items: Vec<ForeignItem>,
17201720
}
17211721

17221722
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
17231723
pub struct EnumDef {
1724-
pub variants: Vec<P<Variant>>,
1724+
pub variants: Vec<Variant>,
17251725
}
17261726

17271727
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@@ -1988,7 +1988,7 @@ pub enum ItemKind {
19881988
Trait(Unsafety,
19891989
Generics,
19901990
TyParamBounds,
1991-
Vec<P<TraitItem>>),
1991+
Vec<TraitItem>),
19921992

19931993
// Default trait implementations
19941994
///
@@ -2000,7 +2000,7 @@ pub enum ItemKind {
20002000
Generics,
20012001
Option<TraitRef>, // (optional) trait this impl implements
20022002
P<Ty>, // self
2003-
Vec<P<ImplItem>>),
2003+
Vec<ImplItem>),
20042004
/// A macro invocation (which includes macro definition)
20052005
Mac(Mac),
20062006
}

src/libsyntax/config.rs

+14-17
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'a, F> fold::Folder for Context<'a, F> where F: FnMut(&[ast::Attribute]) ->
7272
fn fold_opt_expr(&mut self, expr: P<ast::Expr>) -> Option<P<ast::Expr>> {
7373
fold_opt_expr(self, expr)
7474
}
75-
fn fold_stmt(&mut self, stmt: P<ast::Stmt>) -> SmallVector<P<ast::Stmt>> {
75+
fn fold_stmt(&mut self, stmt: ast::Stmt) -> SmallVector<ast::Stmt> {
7676
fold_stmt(self, stmt)
7777
}
7878
fn fold_mac(&mut self, mac: ast::Mac) -> ast::Mac {
@@ -95,8 +95,8 @@ pub fn strip_items<'a, F>(diagnostic: &'a Handler,
9595
}
9696

9797
fn filter_foreign_item<F>(cx: &mut Context<F>,
98-
item: P<ast::ForeignItem>)
99-
-> Option<P<ast::ForeignItem>> where
98+
item: ast::ForeignItem)
99+
-> Option<ast::ForeignItem> where
100100
F: FnMut(&[ast::Attribute]) -> bool
101101
{
102102
if foreign_item_in_cfg(cx, &item) {
@@ -153,18 +153,15 @@ fn fold_item_kind<F>(cx: &mut Context<F>, item: ast::ItemKind) -> ast::ItemKind
153153
if !(cx.in_cfg)(&v.node.attrs) {
154154
None
155155
} else {
156-
Some(v.map(|Spanned {node: ast::Variant_ {name, attrs, data,
157-
disr_expr}, span}| {
158-
Spanned {
159-
node: ast::Variant_ {
160-
name: name,
161-
attrs: attrs,
162-
data: fold_struct(cx, data),
163-
disr_expr: disr_expr,
164-
},
165-
span: span
166-
}
167-
}))
156+
Some(Spanned {
157+
node: ast::Variant_ {
158+
name: v.node.name,
159+
attrs: v.node.attrs,
160+
data: fold_struct(cx, v.node.data),
161+
disr_expr: v.node.disr_expr,
162+
},
163+
span: v.span
164+
})
168165
}
169166
});
170167
ast::ItemKind::Enum(ast::EnumDef {
@@ -225,11 +222,11 @@ fn fold_expr<F>(cx: &mut Context<F>, expr: P<ast::Expr>) -> P<ast::Expr> where
225222
})
226223
}
227224

228-
fn fold_stmt<F>(cx: &mut Context<F>, stmt: P<ast::Stmt>) -> SmallVector<P<ast::Stmt>>
225+
fn fold_stmt<F>(cx: &mut Context<F>, stmt: ast::Stmt) -> SmallVector<ast::Stmt>
229226
where F: FnMut(&[ast::Attribute]) -> bool
230227
{
231228
if stmt_in_cfg(cx, &stmt) {
232-
stmt.and_then(|s| fold::noop_fold_stmt(s, cx))
229+
fold::noop_fold_stmt(stmt, cx)
233230
} else {
234231
SmallVector::zero()
235232
}

src/libsyntax/ext/base.rs

+16-16
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,16 @@ impl Annotatable {
8282
}
8383
}
8484

85-
pub fn expect_trait_item(self) -> P<ast::TraitItem> {
85+
pub fn expect_trait_item(self) -> ast::TraitItem {
8686
match self {
87-
Annotatable::TraitItem(i) => i,
87+
Annotatable::TraitItem(i) => i.unwrap(),
8888
_ => panic!("expected Item")
8989
}
9090
}
9191

92-
pub fn expect_impl_item(self) -> P<ast::ImplItem> {
92+
pub fn expect_impl_item(self) -> ast::ImplItem {
9393
match self {
94-
Annotatable::ImplItem(i) => i,
94+
Annotatable::ImplItem(i) => i.unwrap(),
9595
_ => panic!("expected Item")
9696
}
9797
}
@@ -204,8 +204,8 @@ impl<F> IdentMacroExpander for F
204204
macro_rules! make_stmts_default {
205205
($me:expr) => {
206206
$me.make_expr().map(|e| {
207-
SmallVector::one(P(codemap::respan(
208-
e.span, ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID))))
207+
SmallVector::one(codemap::respan(
208+
e.span, ast::StmtKind::Expr(e, ast::DUMMY_NODE_ID)))
209209
})
210210
}
211211
}
@@ -223,7 +223,7 @@ pub trait MacResult {
223223
}
224224

225225
/// Create zero or more impl items.
226-
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<P<ast::ImplItem>>> {
226+
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<ast::ImplItem>> {
227227
None
228228
}
229229

@@ -236,7 +236,7 @@ pub trait MacResult {
236236
///
237237
/// By default this attempts to create an expression statement,
238238
/// returning None if that fails.
239-
fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
239+
fn make_stmts(self: Box<Self>) -> Option<SmallVector<ast::Stmt>> {
240240
make_stmts_default!(self)
241241
}
242242

@@ -273,8 +273,8 @@ make_MacEager! {
273273
expr: P<ast::Expr>,
274274
pat: P<ast::Pat>,
275275
items: SmallVector<P<ast::Item>>,
276-
impl_items: SmallVector<P<ast::ImplItem>>,
277-
stmts: SmallVector<P<ast::Stmt>>,
276+
impl_items: SmallVector<ast::ImplItem>,
277+
stmts: SmallVector<ast::Stmt>,
278278
ty: P<ast::Ty>,
279279
}
280280

@@ -287,11 +287,11 @@ impl MacResult for MacEager {
287287
self.items
288288
}
289289

290-
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<P<ast::ImplItem>>> {
290+
fn make_impl_items(self: Box<Self>) -> Option<SmallVector<ast::ImplItem>> {
291291
self.impl_items
292292
}
293293

294-
fn make_stmts(self: Box<Self>) -> Option<SmallVector<P<ast::Stmt>>> {
294+
fn make_stmts(self: Box<Self>) -> Option<SmallVector<ast::Stmt>> {
295295
match self.stmts.as_ref().map_or(0, |s| s.len()) {
296296
0 => make_stmts_default!(self),
297297
_ => self.stmts,
@@ -391,19 +391,19 @@ impl MacResult for DummyResult {
391391
}
392392
}
393393

394-
fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVector<P<ast::ImplItem>>> {
394+
fn make_impl_items(self: Box<DummyResult>) -> Option<SmallVector<ast::ImplItem>> {
395395
if self.expr_only {
396396
None
397397
} else {
398398
Some(SmallVector::zero())
399399
}
400400
}
401401

402-
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Stmt>>> {
403-
Some(SmallVector::one(P(
402+
fn make_stmts(self: Box<DummyResult>) -> Option<SmallVector<ast::Stmt>> {
403+
Some(SmallVector::one(
404404
codemap::respan(self.span,
405405
ast::StmtKind::Expr(DummyResult::raw_expr(self.span),
406-
ast::DUMMY_NODE_ID)))))
406+
ast::DUMMY_NODE_ID))))
407407
}
408408
}
409409

0 commit comments

Comments
 (0)