about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorEduard Burtescu <edy.burt@gmail.com>2015-03-05 04:48:54 +0200
committerEduard Burtescu <edy.burt@gmail.com>2015-03-11 23:39:15 +0200
commit98491827b920884e4ea1182dcacce2a650dde861 (patch)
treeea55dc4ff5b7e7007183f78ca8cb0896957df352 /src/libsyntax
parentf899513a30165946a75ff7f515ab37a226e72172 (diff)
downloadrust-98491827b920884e4ea1182dcacce2a650dde861.tar.gz
rust-98491827b920884e4ea1182dcacce2a650dde861.zip
syntax: move indirection around {Trait,Impl}Item, from within.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast.rs12
-rw-r--r--src/libsyntax/ast_map/blocks.rs4
-rw-r--r--src/libsyntax/ast_map/mod.rs52
-rw-r--r--src/libsyntax/ast_util.rs56
-rw-r--r--src/libsyntax/ext/base.rs55
-rw-r--r--src/libsyntax/ext/deriving/generic/mod.rs14
-rw-r--r--src/libsyntax/ext/expand.rs18
-rw-r--r--src/libsyntax/ext/tt/macro_rules.rs2
-rw-r--r--src/libsyntax/fold.rs49
-rw-r--r--src/libsyntax/parse/parser.rs26
-rw-r--r--src/libsyntax/print/pprust.rs19
-rw-r--r--src/libsyntax/visit.rs8
12 files changed, 123 insertions, 192 deletions
diff --git a/src/libsyntax/ast.rs b/src/libsyntax/ast.rs
index 550ce3bb8c8..fafcc056ded 100644
--- a/src/libsyntax/ast.rs
+++ b/src/libsyntax/ast.rs
@@ -1081,14 +1081,14 @@ pub struct TypeMethod {
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub enum TraitItem {
     RequiredMethod(TypeMethod),
-    ProvidedMethod(P<Method>),
-    TypeTraitItem(P<AssociatedType>),
+    ProvidedMethod(Method),
+    TypeTraitItem(AssociatedType),
 }
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
 pub enum ImplItem {
-    MethodImplItem(P<Method>),
-    TypeImplItem(P<Typedef>),
+    MethodImplItem(Method),
+    TypeImplItem(Typedef),
 }
 
 #[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
@@ -1659,7 +1659,7 @@ pub enum Item_ {
     ItemTrait(Unsafety,
               Generics,
               TyParamBounds,
-              Vec<TraitItem>),
+              Vec<P<TraitItem>>),
 
     // Default trait implementations
     // `impl Trait for ..`
@@ -1669,7 +1669,7 @@ pub enum Item_ {
              Generics,
              Option<TraitRef>, // (optional) trait this impl implements
              P<Ty>, // self
-             Vec<ImplItem>),
+             Vec<P<ImplItem>>),
     /// A macro invocation (which includes macro definition)
     ItemMac(Mac),
 }
diff --git a/src/libsyntax/ast_map/blocks.rs b/src/libsyntax/ast_map/blocks.rs
index 1a537c7a5b8..8d605ea50cd 100644
--- a/src/libsyntax/ast_map/blocks.rs
+++ b/src/libsyntax/ast_map/blocks.rs
@@ -206,12 +206,12 @@ impl<'a> FnLikeNode<'a> {
                 _ => panic!("item FnLikeNode that is not fn-like"),
             },
             ast_map::NodeTraitItem(t) => match *t {
-                ast::ProvidedMethod(ref m) => method(&**m),
+                ast::ProvidedMethod(ref m) => method(m),
                 _ => panic!("trait method FnLikeNode that is not fn-like"),
             },
             ast_map::NodeImplItem(ii) => {
                 match *ii {
-                    ast::MethodImplItem(ref m) => method(&**m),
+                    ast::MethodImplItem(ref m) => method(m),
                     ast::TypeImplItem(_) => {
                         panic!("impl method FnLikeNode that is not fn-like")
                     }
diff --git a/src/libsyntax/ast_map/mod.rs b/src/libsyntax/ast_map/mod.rs
index b96d735d92d..4db6f9bc3c5 100644
--- a/src/libsyntax/ast_map/mod.rs
+++ b/src/libsyntax/ast_map/mod.rs
@@ -14,12 +14,11 @@ use self::MapEntry::*;
 
 use abi;
 use ast::*;
-use ast_util;
+use ast_util::{self, PostExpansionMethod};
 use codemap::{DUMMY_SP, Span, Spanned};
 use fold::Folder;
 use parse::token;
 use print::pprust;
-use ptr::P;
 use visit::{self, Visitor};
 
 use arena::TypedArena;
@@ -741,14 +740,11 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
         match i.node {
             ItemImpl(_, _, _, _, _, ref impl_items) => {
                 for impl_item in impl_items {
-                    match *impl_item {
-                        MethodImplItem(ref m) => {
-                            self.insert(m.id, NodeImplItem(impl_item));
-                        }
-                        TypeImplItem(ref t) => {
-                            self.insert(t.id, NodeImplItem(impl_item));
-                        }
-                    }
+                    let id = match **impl_item {
+                        MethodImplItem(ref m) => m.id,
+                        TypeImplItem(ref t) => t.id,
+                    };
+                    self.insert(id, NodeImplItem(impl_item));
                 }
             }
             ItemEnum(ref enum_definition, _) => {
@@ -778,17 +774,12 @@ impl<'ast> Visitor<'ast> for NodeCollector<'ast> {
                 }
 
                 for tm in trait_items {
-                    match *tm {
-                        RequiredMethod(ref m) => {
-                            self.insert(m.id, NodeTraitItem(tm));
-                        }
-                        ProvidedMethod(ref m) => {
-                            self.insert(m.id, NodeTraitItem(tm));
-                        }
-                        TypeTraitItem(ref typ) => {
-                            self.insert(typ.ty_param.id, NodeTraitItem(tm));
-                        }
-                    }
+                    let id = match **tm {
+                        RequiredMethod(ref m) => m.id,
+                        ProvidedMethod(ref m) => m.id,
+                        TypeTraitItem(ref typ) => typ.ty_param.id,
+                    };
+                    self.insert(id, NodeTraitItem(tm));
                 }
             }
             _ => {}
@@ -933,7 +924,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
             TypeTraitItem(at) => {
                 IITraitItem(
                     fld.fold_ops.new_def_id(d),
-                    TypeTraitItem(P(fld.fold_associated_type((*at).clone()))))
+                    TypeTraitItem(fld.fold_associated_type(at)))
             }
         },
         IIImplItem(d, m) => match m {
@@ -944,7 +935,7 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
             }
             TypeImplItem(t) => {
                 IIImplItem(fld.fold_ops.new_def_id(d),
-                           TypeImplItem(P(fld.fold_typedef((*t).clone()))))
+                           TypeImplItem(fld.fold_typedef(t)))
             }
         },
         IIForeign(i) => IIForeign(fld.fold_foreign_item(i))
@@ -1064,7 +1055,7 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
                     }
                 }
                 TypeImplItem(ref t) => {
-                    format!("typedef {} in {}{}",
+                    format!("assoc type {} in {}{}",
                             token::get_ident(t.ident),
                             map.path_to_string(id),
                             id_str)
@@ -1073,15 +1064,20 @@ fn node_id_to_string(map: &Map, id: NodeId, include_id: bool) -> String {
         }
         Some(NodeTraitItem(ref tm)) => {
             match **tm {
-                RequiredMethod(_) | ProvidedMethod(_) => {
-                    let m = ast_util::trait_item_to_ty_method(&**tm);
-                    format!("method {} in {}{}",
+                RequiredMethod(ref m) => {
+                    format!("required method {} in {}{}",
                             token::get_ident(m.ident),
                             map.path_to_string(id),
                             id_str)
                 }
+                ProvidedMethod(ref m) => {
+                    format!("provided method {} in {}{}",
+                            token::get_ident(m.pe_ident()),
+                            map.path_to_string(id),
+                            id_str)
+                }
                 TypeTraitItem(ref t) => {
-                    format!("type item {} in {}{}",
+                    format!("assoc type {} in {}{}",
                             token::get_ident(t.ty_param.ident),
                             map.path_to_string(id),
                             id_str)
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 26d7562cdb2..a8804b595d4 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -268,62 +268,6 @@ pub fn impl_pretty_name(trait_ref: &Option<TraitRef>, ty: Option<&Ty>) -> Ident
     token::gensym_ident(&pretty[..])
 }
 
-pub fn trait_method_to_ty_method(method: &Method) -> TypeMethod {
-    match method.node {
-        MethDecl(ident,
-                 ref generics,
-                 abi,
-                 ref explicit_self,
-                 unsafety,
-                 ref decl,
-                 _,
-                 vis) => {
-            TypeMethod {
-                ident: ident,
-                attrs: method.attrs.clone(),
-                unsafety: unsafety,
-                decl: (*decl).clone(),
-                generics: generics.clone(),
-                explicit_self: (*explicit_self).clone(),
-                id: method.id,
-                span: method.span,
-                vis: vis,
-                abi: abi,
-            }
-        },
-        MethMac(_) => panic!("expected non-macro method declaration")
-    }
-}
-
-/// extract a TypeMethod from a TraitItem. if the TraitItem is
-/// a default, pull out the useful fields to make a TypeMethod
-//
-// NB: to be used only after expansion is complete, and macros are gone.
-pub fn trait_item_to_ty_method(method: &TraitItem) -> TypeMethod {
-    match *method {
-        RequiredMethod(ref m) => (*m).clone(),
-        ProvidedMethod(ref m) => trait_method_to_ty_method(&**m),
-        TypeTraitItem(_) => {
-            panic!("trait_method_to_ty_method(): expected method but found \
-                   typedef")
-        }
-    }
-}
-
-pub fn split_trait_methods(trait_methods: &[TraitItem])
-                           -> (Vec<TypeMethod>, Vec<P<Method>> ) {
-    let mut reqd = Vec::new();
-    let mut provd = Vec::new();
-    for trt_method in trait_methods {
-        match *trt_method {
-            RequiredMethod(ref tm) => reqd.push((*tm).clone()),
-            ProvidedMethod(ref m) => provd.push((*m).clone()),
-            TypeTraitItem(_) => {}
-        }
-    };
-    (reqd, provd)
-}
-
 pub fn struct_field_visibility(field: ast::StructField) -> Visibility {
     match field.node.kind {
         ast::NamedField(_, v) | ast::UnnamedField(v) => v
diff --git a/src/libsyntax/ext/base.rs b/src/libsyntax/ext/base.rs
index 8aeafe419da..b999680ff1a 100644
--- a/src/libsyntax/ext/base.rs
+++ b/src/libsyntax/ext/base.rs
@@ -86,42 +86,37 @@ impl Annotatable {
         match *self {
             Annotatable::Item(ref i) => &i.attrs,
             Annotatable::TraitItem(ref i) => match *i {
-                ast::TraitItem::RequiredMethod(ref tm) => &tm.attrs,
-                ast::TraitItem::ProvidedMethod(ref m) => &m.attrs,
-                ast::TraitItem::TypeTraitItem(ref at) => &at.attrs,
+                ast::RequiredMethod(ref tm) => &tm.attrs,
+                ast::ProvidedMethod(ref m) => &m.attrs,
+                ast::TypeTraitItem(ref at) => &at.attrs,
             },
             Annotatable::ImplItem(ref i) => match *i {
-                ast::ImplItem::MethodImplItem(ref m) => &m.attrs,
-                ast::ImplItem::TypeImplItem(ref t) => &t.attrs,
+                ast::MethodImplItem(ref m) => &m.attrs,
+                ast::TypeImplItem(ref t) => &t.attrs,
             }
         }
     }
 
     pub fn fold_attrs(self, attrs: Vec<ast::Attribute>) -> Annotatable {
         match self {
-            Annotatable::Item(i) => Annotatable::Item(P(ast::Item {
+            Annotatable::Item(i) => Annotatable::Item(i.map(|i| ast::Item {
                 attrs: attrs,
-                ..(*i).clone()
+                ..i
             })),
-            Annotatable::TraitItem(i) => match i {
-                ast::TraitItem::RequiredMethod(tm) => Annotatable::TraitItem(
-                    ast::TraitItem::RequiredMethod(
-                        ast::TypeMethod { attrs: attrs, ..tm })),
-                ast::TraitItem::ProvidedMethod(m) => Annotatable::TraitItem(
-                    ast::TraitItem::ProvidedMethod(P(
-                        ast::Method { attrs: attrs, ..(*m).clone() }))),
-                ast::TraitItem::TypeTraitItem(at) => Annotatable::TraitItem(
-                    ast::TraitItem::TypeTraitItem(P(
-                        ast::AssociatedType { attrs: attrs, ..(*at).clone() }))),
-            },
-            Annotatable::ImplItem(i) => match i {
-                ast::ImplItem::MethodImplItem(m) => Annotatable::ImplItem(
-                    ast::ImplItem::MethodImplItem(P(
-                        ast::Method { attrs: attrs, ..(*m).clone() }))),
-                ast::ImplItem::TypeImplItem(t) => Annotatable::ImplItem(
-                    ast::ImplItem::TypeImplItem(P(
-                        ast::Typedef { attrs: attrs, ..(*t).clone() }))),
-            }
+            Annotatable::TraitItem(i) => Annotatable::TraitItem(match i {
+                ast::RequiredMethod(tm) =>
+                    ast::RequiredMethod(ast::TypeMethod { attrs: attrs, ..tm }),
+                ast::ProvidedMethod(m) =>
+                    ast::ProvidedMethod(ast::Method { attrs: attrs, ..m }),
+                ast::TypeTraitItem(at) =>
+                    ast::TypeTraitItem(ast::AssociatedType { attrs: attrs, ..at }),
+            }),
+            Annotatable::ImplItem(i) => Annotatable::ImplItem(match i {
+                ast::MethodImplItem(m) =>
+                    ast::MethodImplItem(ast::Method { attrs: attrs, ..m }),
+                ast::TypeImplItem(t) =>
+                    ast::TypeImplItem(ast::Typedef { attrs: attrs, ..t }),
+            })
         }
     }
 
@@ -249,7 +244,7 @@ pub trait MacResult {
     }
 
     /// Create zero or more methods.
-    fn make_methods(self: Box<Self>) -> Option<SmallVector<P<ast::Method>>> {
+    fn make_methods(self: Box<Self>) -> Option<SmallVector<ast::Method>> {
         None
     }
 
@@ -295,7 +290,7 @@ make_MacEager! {
     expr: P<ast::Expr>,
     pat: P<ast::Pat>,
     items: SmallVector<P<ast::Item>>,
-    methods: SmallVector<P<ast::Method>>,
+    methods: SmallVector<ast::Method>,
     stmt: P<ast::Stmt>,
 }
 
@@ -308,7 +303,7 @@ impl MacResult for MacEager {
         self.items
     }
 
-    fn make_methods(self: Box<Self>) -> Option<SmallVector<P<ast::Method>>> {
+    fn make_methods(self: Box<Self>) -> Option<SmallVector<ast::Method>> {
         self.methods
     }
 
@@ -397,7 +392,7 @@ impl MacResult for DummyResult {
             Some(SmallVector::zero())
         }
     }
-    fn make_methods(self: Box<DummyResult>) -> Option<SmallVector<P<ast::Method>>> {
+    fn make_methods(self: Box<DummyResult>) -> Option<SmallVector<ast::Method>> {
         if self.expr_only {
             None
         } else {
diff --git a/src/libsyntax/ext/deriving/generic/mod.rs b/src/libsyntax/ext/deriving/generic/mod.rs
index 9cd965a8138..0573289150c 100644
--- a/src/libsyntax/ext/deriving/generic/mod.rs
+++ b/src/libsyntax/ext/deriving/generic/mod.rs
@@ -386,12 +386,12 @@ impl<'a> TraitDef<'a> {
                            cx: &mut ExtCtxt,
                            type_ident: Ident,
                            generics: &Generics,
-                           methods: Vec<P<ast::Method>>) -> P<ast::Item> {
+                           methods: Vec<ast::Method>) -> P<ast::Item> {
         let trait_path = self.path.to_path(cx, self.span, type_ident, generics);
 
         // Transform associated types from `deriving::ty::Ty` into `ast::Typedef`
         let associated_types = self.associated_types.iter().map(|&(ident, ref type_def)| {
-            P(ast::Typedef {
+            ast::Typedef {
                 id: ast::DUMMY_NODE_ID,
                 span: self.span,
                 ident: ident,
@@ -402,7 +402,7 @@ impl<'a> TraitDef<'a> {
                     type_ident,
                     generics
                 ),
-            })
+            }
         });
 
         let Generics { mut lifetimes, ty_params, mut where_clause } =
@@ -517,7 +517,7 @@ impl<'a> TraitDef<'a> {
                                      associated_types.map(|type_| {
                                          ast::TypeImplItem(type_)
                                      })
-                                 ).collect()))
+                                 ).map(P).collect()))
     }
 
     fn expand_struct_def(&self,
@@ -702,7 +702,7 @@ impl<'a> MethodDef<'a> {
                      abi: Abi,
                      explicit_self: ast::ExplicitSelf,
                      arg_types: Vec<(Ident, P<ast::Ty>)> ,
-                     body: P<Expr>) -> P<ast::Method> {
+                     body: P<Expr>) -> ast::Method {
         // create the generics that aren't for Self
         let fn_generics = self.generics.to_generics(cx, trait_.span, type_ident, generics);
 
@@ -725,7 +725,7 @@ impl<'a> MethodDef<'a> {
         let body_block = cx.block_expr(body);
 
         // Create the method.
-        P(ast::Method {
+        ast::Method {
             attrs: self.attributes.clone(),
             id: ast::DUMMY_NODE_ID,
             span: trait_.span,
@@ -737,7 +737,7 @@ impl<'a> MethodDef<'a> {
                                 fn_decl,
                                 body_block,
                                 ast::Inherited)
-        })
+        }
     }
 
     /// ```
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 98c7aefcd8a..96859b94f1d 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -1185,7 +1185,7 @@ fn expand_annotatable(a: Annotatable,
             }
             ast::TraitItem::TypeTraitItem(t) => {
                 SmallVector::one(Annotatable::TraitItem(
-                    ast::TraitItem::TypeTraitItem(P(fld.fold_associated_type((*t).clone())))))
+                    ast::TraitItem::TypeTraitItem(fld.fold_associated_type(t))))
             }
         },
         Annotatable::ImplItem(it) => match it {
@@ -1195,7 +1195,7 @@ fn expand_annotatable(a: Annotatable,
             }
             ast::ImplItem::TypeImplItem(t) => {
                 SmallVector::one(Annotatable::ImplItem(
-                    ast::ImplItem::TypeImplItem(P(fld.fold_typedef((*t).clone())))))
+                    ast::ImplItem::TypeImplItem(fld.fold_typedef(t))))
             }
         }
     };
@@ -1293,8 +1293,8 @@ fn expand_item_multi_modifier(mut it: Annotatable,
 }
 
 // expand a method
-fn expand_method(m: P<ast::Method>, fld: &mut MacroExpander) -> SmallVector<P<ast::Method>> {
-    m.and_then(|m| match m.node {
+fn expand_method(m: ast::Method, fld: &mut MacroExpander) -> SmallVector<ast::Method> {
+    match m.node {
         ast::MethDecl(ident,
                       generics,
                       abi,
@@ -1306,7 +1306,7 @@ fn expand_method(m: P<ast::Method>, fld: &mut MacroExpander) -> SmallVector<P<as
             let id = fld.new_id(m.id);
             let (rewritten_fn_decl, rewritten_body)
                 = expand_and_rename_fn_decl_and_block(decl, body, fld);
-            SmallVector::one(P(ast::Method {
+            SmallVector::one(ast::Method {
                     attrs: fold::fold_attrs(m.attrs, fld),
                     id: id,
                     span: fld.new_span(m.span),
@@ -1318,7 +1318,7 @@ fn expand_method(m: P<ast::Method>, fld: &mut MacroExpander) -> SmallVector<P<as
                                         rewritten_fn_decl,
                                         rewritten_body,
                                         vis)
-                }))
+                })
         },
         ast::MethMac(mac) => {
             let maybe_new_methods =
@@ -1339,7 +1339,7 @@ fn expand_method(m: P<ast::Method>, fld: &mut MacroExpander) -> SmallVector<P<as
                 None => SmallVector::zero()
             }
         }
-    })
+    }
 }
 
 /// Given a fn_decl and a block and a MacroExpander, expand the fn_decl, then use the
@@ -1418,7 +1418,7 @@ impl<'a, 'b> Folder for MacroExpander<'a, 'b> {
         expand_impl_item(i, self)
     }
 
-    fn fold_method(&mut self, method: P<ast::Method>) -> SmallVector<P<ast::Method>> {
+    fn fold_method(&mut self, method: ast::Method) -> SmallVector<ast::Method> {
         expand_method(method, self)
     }
 
@@ -1565,7 +1565,7 @@ fn mark_item(expr: P<ast::Item>, m: Mrk) -> P<ast::Item> {
 }
 
 // apply a given mark to the given item. Used following the expansion of a macro.
-fn mark_method(expr: P<ast::Method>, m: Mrk) -> P<ast::Method> {
+fn mark_method(expr: ast::Method, m: Mrk) -> ast::Method {
     Marker{mark:m}.fold_method(expr)
         .expect_one("marking an item didn't return exactly one method")
 }
diff --git a/src/libsyntax/ext/tt/macro_rules.rs b/src/libsyntax/ext/tt/macro_rules.rs
index 644c6cd7e28..dcdfad4632d 100644
--- a/src/libsyntax/ext/tt/macro_rules.rs
+++ b/src/libsyntax/ext/tt/macro_rules.rs
@@ -82,7 +82,7 @@ impl<'a> MacResult for ParserAnyMacro<'a> {
         Some(ret)
     }
 
-    fn make_methods(self: Box<ParserAnyMacro<'a>>) -> Option<SmallVector<P<ast::Method>>> {
+    fn make_methods(self: Box<ParserAnyMacro<'a>>) -> Option<SmallVector<ast::Method>> {
         let mut ret = SmallVector::zero();
         loop {
             let mut parser = self.parser.borrow_mut();
diff --git a/src/libsyntax/fold.rs b/src/libsyntax/fold.rs
index 959e3bdb314..5109a19fdb6 100644
--- a/src/libsyntax/fold.rs
+++ b/src/libsyntax/fold.rs
@@ -98,11 +98,11 @@ pub trait Folder : Sized {
         noop_fold_item_underscore(i, self)
     }
 
-    fn fold_trait_item(&mut self, i: TraitItem) -> SmallVector<TraitItem> {
+    fn fold_trait_item(&mut self, i: P<TraitItem>) -> SmallVector<P<TraitItem>> {
         noop_fold_trait_item(i, self)
     }
 
-    fn fold_impl_item(&mut self, i: ImplItem) -> SmallVector<ImplItem> {
+    fn fold_impl_item(&mut self, i: P<ImplItem>) -> SmallVector<P<ImplItem>> {
         noop_fold_impl_item(i, self)
     }
 
@@ -114,7 +114,7 @@ pub trait Folder : Sized {
         noop_fold_type_method(m, self)
     }
 
-    fn fold_method(&mut self, m: P<Method>) -> SmallVector<P<Method>> {
+    fn fold_method(&mut self, m: Method) -> SmallVector<Method> {
         noop_fold_method(m, self)
     }
 
@@ -1018,34 +1018,30 @@ pub fn noop_fold_item_underscore<T: Folder>(i: Item_, folder: &mut T) -> Item_ {
     }
 }
 
-pub fn noop_fold_trait_item<T: Folder>(i: TraitItem, folder: &mut T) -> SmallVector<TraitItem> {
-    match i {
-        RequiredMethod(m) => {
-                SmallVector::one(RequiredMethod(
-                        folder.fold_type_method(m)))
-        }
+pub fn noop_fold_trait_item<T: Folder>(i: P<TraitItem>, folder: &mut T)
+                                       -> SmallVector<P<TraitItem>> {
+    i.map(|i| SmallVector::one(P(match i {
+        RequiredMethod(m) => RequiredMethod(folder.fold_type_method(m)),
         ProvidedMethod(method) => {
-            folder.fold_method(method).into_iter()
-                .map(|m| ProvidedMethod(m)).collect()
+            return folder.fold_method(method).into_iter()
+                         .map(|m| P(ProvidedMethod(m))).collect();
         }
         TypeTraitItem(at) => {
-            SmallVector::one(TypeTraitItem(P(
-                        folder.fold_associated_type(
-                            (*at).clone()))))
+            TypeTraitItem(folder.fold_associated_type(at))
         }
-    }
+    })))
 }
 
-pub fn noop_fold_impl_item<T: Folder>(i: ImplItem, folder: &mut T) -> SmallVector<ImplItem> {
-    match i {
-        MethodImplItem(ref x) => {
-            folder.fold_method((*x).clone()).into_iter().map(|m| MethodImplItem(m)).collect()
+pub fn noop_fold_impl_item<T: Folder>(i: P<ImplItem>, folder: &mut T)
+                                      -> SmallVector<P<ImplItem>> {
+    i.and_then(|i| match i {
+        MethodImplItem(x) => {
+            folder.fold_method(x).into_iter().map(|m| P(MethodImplItem(m))).collect()
         }
-        TypeImplItem(ref t) => {
-            SmallVector::one(TypeImplItem(
-                    P(folder.fold_typedef((**t).clone()))))
+        TypeImplItem(t) => {
+            SmallVector::one(TypeImplItem(folder.fold_typedef(t)))
         }
-    }
+    })
 }
 
 pub fn noop_fold_type_method<T: Folder>(m: TypeMethod, fld: &mut T) -> TypeMethod {
@@ -1173,8 +1169,9 @@ pub fn noop_fold_foreign_item<T: Folder>(ni: P<ForeignItem>, folder: &mut T) ->
 
 // Default fold over a method.
 // Invariant: produces exactly one method.
-pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<P<Method>> {
-    SmallVector::one(m.map(|Method {id, attrs, node, span}| Method {
+pub fn noop_fold_method<T: Folder>(Method {id, attrs, node, span}: Method, folder: &mut T)
+                                   -> SmallVector<Method> {
+    SmallVector::one(Method {
         id: folder.new_id(id),
         attrs: fold_attrs(attrs, folder),
         node: match node {
@@ -1198,7 +1195,7 @@ pub fn noop_fold_method<T: Folder>(m: P<Method>, folder: &mut T) -> SmallVector<
             MethMac(mac) => MethMac(folder.fold_mac(mac)),
         },
         span: folder.new_span(span)
-    }))
+    })
 }
 
 pub fn noop_fold_pat<T: Folder>(p: P<Pat>, folder: &mut T) -> P<Pat> {
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index 28d757e9be9..63c0f4e1cfa 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -1307,7 +1307,7 @@ impl<'a> Parser<'a> {
     }
 
     /// Parse the items in a trait declaration
-    pub fn parse_trait_items(&mut self) -> Vec<TraitItem> {
+    pub fn parse_trait_items(&mut self) -> Vec<P<TraitItem>> {
         self.parse_unspanned_seq(
             &token::OpenDelim(token::Brace),
             &token::CloseDelim(token::Brace),
@@ -1316,7 +1316,7 @@ impl<'a> Parser<'a> {
             let attrs = p.parse_outer_attributes();
 
             if p.eat_keyword(keywords::Type) {
-                TypeTraitItem(P(p.parse_associated_type(attrs)))
+                P(TypeTraitItem(p.parse_associated_type(attrs)))
             } else {
                 let lo = p.span.lo;
 
@@ -1346,7 +1346,7 @@ impl<'a> Parser<'a> {
                   token::Semi => {
                     p.bump();
                     debug!("parse_trait_methods(): parsing required method");
-                    RequiredMethod(TypeMethod {
+                    P(RequiredMethod(TypeMethod {
                         ident: ident,
                         attrs: attrs,
                         unsafety: style,
@@ -1357,7 +1357,7 @@ impl<'a> Parser<'a> {
                         id: ast::DUMMY_NODE_ID,
                         span: mk_sp(lo, hi),
                         vis: vis,
-                    })
+                    }))
                   }
                   token::OpenDelim(token::Brace) => {
                     debug!("parse_trait_methods(): parsing provided method");
@@ -1365,7 +1365,7 @@ impl<'a> Parser<'a> {
                         p.parse_inner_attrs_and_block();
                     let mut attrs = attrs;
                     attrs.push_all(&inner_attrs[..]);
-                    ProvidedMethod(P(ast::Method {
+                    P(ProvidedMethod(ast::Method {
                         attrs: attrs,
                         id: ast::DUMMY_NODE_ID,
                         span: mk_sp(lo, hi),
@@ -4692,7 +4692,7 @@ impl<'a> Parser<'a> {
     }
 
     /// Parse a method in a trait impl
-    pub fn parse_method_with_outer_attributes(&mut self) -> P<Method> {
+    pub fn parse_method_with_outer_attributes(&mut self) -> Method {
         let attrs = self.parse_outer_attributes();
         let visa = self.parse_visibility();
         self.parse_method(attrs, visa)
@@ -4713,7 +4713,7 @@ impl<'a> Parser<'a> {
     pub fn parse_method(&mut self,
                         attrs: Vec<Attribute>,
                         visa: Visibility)
-                        -> P<Method> {
+                        -> Method {
         let lo = self.span.lo;
 
         // code copied from parse_macro_use_or_failure... abstraction!
@@ -4772,12 +4772,12 @@ impl<'a> Parser<'a> {
                  body_span.hi, new_attrs)
             }
         };
-        P(ast::Method {
+        ast::Method {
             attrs: new_attrs,
             id: ast::DUMMY_NODE_ID,
             span: mk_sp(lo, hi),
             node: method_,
-        })
+        }
     }
 
     /// Parse trait Foo { ... }
@@ -4808,7 +4808,7 @@ impl<'a> Parser<'a> {
         (ident, ItemTrait(unsafety, tps, bounds, meths), None)
     }
 
-    fn parse_impl_items(&mut self) -> (Vec<ImplItem>, Vec<Attribute>) {
+    fn parse_impl_items(&mut self) -> (Vec<P<ImplItem>>, Vec<Attribute>) {
         let mut impl_items = Vec::new();
         self.expect(&token::OpenDelim(token::Brace));
         let (inner_attrs, mut method_attrs) =
@@ -4821,13 +4821,13 @@ impl<'a> Parser<'a> {
 
             let vis = self.parse_visibility();
             if self.eat_keyword(keywords::Type) {
-                impl_items.push(TypeImplItem(P(self.parse_typedef(
+                impl_items.push(P(TypeImplItem(self.parse_typedef(
                             method_attrs,
                             vis))))
             } else {
-                impl_items.push(MethodImplItem(self.parse_method(
+                impl_items.push(P(MethodImplItem(self.parse_method(
                             method_attrs,
-                            vis)));
+                            vis))));
             }
             method_attrs = vec![];
         }
diff --git a/src/libsyntax/print/pprust.rs b/src/libsyntax/print/pprust.rs
index 883c2295a36..863c000dd40 100644
--- a/src/libsyntax/print/pprust.rs
+++ b/src/libsyntax/print/pprust.rs
@@ -12,8 +12,7 @@ pub use self::AnnNode::*;
 
 use abi;
 use ast;
-use ast::{MethodImplItem, RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
-use ast::{RequiredMethod, ProvidedMethod, TypeImplItem, TypeTraitItem};
+use ast::{RegionTyParamBound, TraitTyParamBound, TraitBoundModifier};
 use ast_util;
 use attr;
 use owned_slice::OwnedSlice;
@@ -977,12 +976,12 @@ impl<'a> State<'a> {
                 try!(self.bopen());
                 try!(self.print_inner_attributes(&item.attrs));
                 for impl_item in impl_items {
-                    match *impl_item {
+                    match **impl_item {
                         ast::MethodImplItem(ref meth) => {
-                            try!(self.print_method(&**meth));
+                            try!(self.print_method(meth));
                         }
                         ast::TypeImplItem(ref typ) => {
-                            try!(self.print_typedef(&**typ));
+                            try!(self.print_typedef(typ));
                         }
                     }
                 }
@@ -1258,16 +1257,16 @@ impl<'a> State<'a> {
     pub fn print_trait_method(&mut self,
                               m: &ast::TraitItem) -> io::Result<()> {
         match *m {
-            RequiredMethod(ref ty_m) => self.print_ty_method(ty_m),
-            ProvidedMethod(ref m) => self.print_method(&**m),
-            TypeTraitItem(ref t) => self.print_associated_type(&**t),
+            ast::RequiredMethod(ref ty_m) => self.print_ty_method(ty_m),
+            ast::ProvidedMethod(ref m) => self.print_method(m),
+            ast::TypeTraitItem(ref t) => self.print_associated_type(t),
         }
     }
 
     pub fn print_impl_item(&mut self, ii: &ast::ImplItem) -> io::Result<()> {
         match *ii {
-            MethodImplItem(ref m) => self.print_method(&**m),
-            TypeImplItem(ref td) => self.print_typedef(&**td),
+            ast::MethodImplItem(ref m) => self.print_method(m),
+            ast::TypeImplItem(ref td) => self.print_typedef(td),
         }
     }
 
diff --git a/src/libsyntax/visit.rs b/src/libsyntax/visit.rs
index 33d8d56b4b1..4222bd58a07 100644
--- a/src/libsyntax/visit.rs
+++ b/src/libsyntax/visit.rs
@@ -144,7 +144,7 @@ pub fn walk_inlined_item<'v,V>(visitor: &mut V, item: &'v InlinedItem)
         IIForeign(ref i) => visitor.visit_foreign_item(&**i),
         IITraitItem(_, ref ti) => visitor.visit_trait_item(ti),
         IIImplItem(_, MethodImplItem(ref m)) => {
-            walk_method_helper(visitor, &**m)
+            walk_method_helper(visitor, m)
         }
         IIImplItem(_, TypeImplItem(ref typedef)) => {
             visitor.visit_ident(typedef.span, typedef.ident);
@@ -294,9 +294,9 @@ pub fn walk_item<'v, V: Visitor<'v>>(visitor: &mut V, item: &'v Item) {
             }
             visitor.visit_ty(&**typ);
             for impl_item in impl_items {
-                match *impl_item {
+                match **impl_item {
                     MethodImplItem(ref method) => {
-                        walk_method_helper(visitor, &**method)
+                        walk_method_helper(visitor, method)
                     }
                     TypeImplItem(ref typedef) => {
                         visitor.visit_ident(typedef.span, typedef.ident);
@@ -678,7 +678,7 @@ pub fn walk_ty_method<'v, V: Visitor<'v>>(visitor: &mut V, method_type: &'v Type
 pub fn walk_trait_item<'v, V: Visitor<'v>>(visitor: &mut V, trait_method: &'v TraitItem) {
     match *trait_method {
         RequiredMethod(ref method_type) => visitor.visit_ty_method(method_type),
-        ProvidedMethod(ref method) => walk_method_helper(visitor, &**method),
+        ProvidedMethod(ref method) => walk_method_helper(visitor, method),
         TypeTraitItem(ref associated_type) => {
             walk_ty_param(visitor, &associated_type.ty_param);
         }