diff options
| author | Eduard Burtescu <edy.burt@gmail.com> | 2015-03-05 04:48:54 +0200 |
|---|---|---|
| committer | Eduard Burtescu <edy.burt@gmail.com> | 2015-03-11 23:39:15 +0200 |
| commit | 98491827b920884e4ea1182dcacce2a650dde861 (patch) | |
| tree | ea55dc4ff5b7e7007183f78ca8cb0896957df352 /src/libsyntax/ext | |
| parent | f899513a30165946a75ff7f515ab37a226e72172 (diff) | |
| download | rust-98491827b920884e4ea1182dcacce2a650dde861.tar.gz rust-98491827b920884e4ea1182dcacce2a650dde861.zip | |
syntax: move indirection around {Trait,Impl}Item, from within.
Diffstat (limited to 'src/libsyntax/ext')
| -rw-r--r-- | src/libsyntax/ext/base.rs | 55 | ||||
| -rw-r--r-- | src/libsyntax/ext/deriving/generic/mod.rs | 14 | ||||
| -rw-r--r-- | src/libsyntax/ext/expand.rs | 18 | ||||
| -rw-r--r-- | src/libsyntax/ext/tt/macro_rules.rs | 2 |
4 files changed, 42 insertions, 47 deletions
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(); |
