diff --git a/src/libsyntax/ext/deriving/clone.rs b/src/libsyntax/ext/deriving/clone.rs index e0b493cd8d9..51024158822 100644 --- a/src/libsyntax/ext/deriving/clone.rs +++ b/src/libsyntax/ext/deriving/clone.rs @@ -13,12 +13,15 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; pub fn expand_deriving_clone(cx: &mut ExtCtxt, span: Span, mitem: @MetaItem, item: @Item, push: |@Item|) { + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -32,7 +35,7 @@ pub fn expand_deriving_clone(cx: &mut ExtCtxt, explicit_self: borrowed_explicit_self(), args: Vec::new(), ret_ty: Self, - inline: true, + attributes: attrs, const_nonmatching: false, combine_substructure: combine_substructure(|c, s, sub| { cs_clone("Clone", c, s, sub) diff --git a/src/libsyntax/ext/deriving/cmp/eq.rs b/src/libsyntax/ext/deriving/cmp/eq.rs index 35b7e7c1a66..92b3788c247 100644 --- a/src/libsyntax/ext/deriving/cmp/eq.rs +++ b/src/libsyntax/ext/deriving/cmp/eq.rs @@ -13,6 +13,7 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; pub fn expand_deriving_eq(cx: &mut ExtCtxt, span: Span, @@ -31,20 +32,22 @@ pub fn expand_deriving_eq(cx: &mut ExtCtxt, } macro_rules! md ( - ($name:expr, $f:ident) => { + ($name:expr, $f:ident) => { { + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); MethodDef { name: $name, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec!(borrowed_self()), ret_ty: Literal(Path::new(vec!("bool"))), - inline: true, + attributes: attrs, const_nonmatching: true, combine_substructure: combine_substructure(|a, b, c| { $f(a, b, c) }) } - } + } } ); let trait_def = TraitDef { diff --git a/src/libsyntax/ext/deriving/cmp/ord.rs b/src/libsyntax/ext/deriving/cmp/ord.rs index afe2d3dae6a..dd2f90cfa5f 100644 --- a/src/libsyntax/ext/deriving/cmp/ord.rs +++ b/src/libsyntax/ext/deriving/cmp/ord.rs @@ -14,6 +14,7 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; pub fn expand_deriving_ord(cx: &mut ExtCtxt, span: Span, @@ -21,20 +22,22 @@ pub fn expand_deriving_ord(cx: &mut ExtCtxt, item: @Item, push: |@Item|) { macro_rules! md ( - ($name:expr, $op:expr, $equal:expr) => { + ($name:expr, $op:expr, $equal:expr) => { { + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); MethodDef { name: $name, generics: LifetimeBounds::empty(), explicit_self: borrowed_explicit_self(), args: vec!(borrowed_self()), ret_ty: Literal(Path::new(vec!("bool"))), - inline: true, + attributes: attrs, const_nonmatching: false, combine_substructure: combine_substructure(|cx, span, substr| { cs_op($op, $equal, cx, span, substr) }) } - } + } } ); let trait_def = TraitDef { diff --git a/src/libsyntax/ext/deriving/cmp/totaleq.rs b/src/libsyntax/ext/deriving/cmp/totaleq.rs index d161f966850..b76caccffec 100644 --- a/src/libsyntax/ext/deriving/cmp/totaleq.rs +++ b/src/libsyntax/ext/deriving/cmp/totaleq.rs @@ -13,6 +13,7 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, span: Span, @@ -33,6 +34,11 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, substr) } + let inline = cx.meta_word(span, InternedString::new("inline")); + let hidden = cx.meta_word(span, InternedString::new("hidden")); + let doc = cx.meta_list(span, InternedString::new("doc"), vec!(hidden)); + let attrs = vec!(cx.attribute(span, inline), + cx.attribute(span, doc)); let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -46,7 +52,7 @@ pub fn expand_deriving_totaleq(cx: &mut ExtCtxt, explicit_self: borrowed_explicit_self(), args: vec!(), ret_ty: nil_ty(), - inline: true, + attributes: attrs, const_nonmatching: true, combine_substructure: combine_substructure(|a, b, c| { cs_total_eq_assert(a, b, c) diff --git a/src/libsyntax/ext/deriving/cmp/totalord.rs b/src/libsyntax/ext/deriving/cmp/totalord.rs index 69c413890e9..3ca4f9e2862 100644 --- a/src/libsyntax/ext/deriving/cmp/totalord.rs +++ b/src/libsyntax/ext/deriving/cmp/totalord.rs @@ -14,6 +14,7 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; use std::cmp::{Ordering, Equal, Less, Greater}; @@ -22,6 +23,8 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt, mitem: @MetaItem, item: @Item, push: |@Item|) { + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -35,7 +38,7 @@ pub fn expand_deriving_totalord(cx: &mut ExtCtxt, explicit_self: borrowed_explicit_self(), args: vec!(borrowed_self()), ret_ty: Literal(Path::new(vec!("std", "cmp", "Ordering"))), - inline: true, + attributes: attrs, const_nonmatching: false, combine_substructure: combine_substructure(|a, b, c| { cs_cmp(a, b, c) diff --git a/src/libsyntax/ext/deriving/decodable.rs b/src/libsyntax/ext/deriving/decodable.rs index 6d6cdc55d40..062f198425b 100644 --- a/src/libsyntax/ext/deriving/decodable.rs +++ b/src/libsyntax/ext/deriving/decodable.rs @@ -50,7 +50,7 @@ pub fn expand_deriving_decodable(cx: &mut ExtCtxt, Borrowed(None, MutMutable))), ret_ty: Literal(Path::new_(vec!("std", "result", "Result"), None, vec!(~Self, ~Literal(Path::new_local("__E"))), true)), - inline: false, + attributes: Vec::new(), const_nonmatching: true, combine_substructure: combine_substructure(|a, b, c| { decodable_substructure(a, b, c) diff --git a/src/libsyntax/ext/deriving/default.rs b/src/libsyntax/ext/deriving/default.rs index 633674eff5c..c225906ed2b 100644 --- a/src/libsyntax/ext/deriving/default.rs +++ b/src/libsyntax/ext/deriving/default.rs @@ -13,12 +13,15 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; pub fn expand_deriving_default(cx: &mut ExtCtxt, span: Span, mitem: @MetaItem, item: @Item, push: |@Item|) { + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -32,7 +35,7 @@ pub fn expand_deriving_default(cx: &mut ExtCtxt, explicit_self: None, args: Vec::new(), ret_ty: Self, - inline: true, + attributes: attrs, const_nonmatching: false, combine_substructure: combine_substructure(|a, b, c| { default_substructure(a, b, c) diff --git a/src/libsyntax/ext/deriving/encodable.rs b/src/libsyntax/ext/deriving/encodable.rs index acdef8c8645..ec3d4e0078b 100644 --- a/src/libsyntax/ext/deriving/encodable.rs +++ b/src/libsyntax/ext/deriving/encodable.rs @@ -121,7 +121,7 @@ pub fn expand_deriving_encodable(cx: &mut ExtCtxt, vec!(~Tuple(Vec::new()), ~Literal(Path::new_local("__E"))), true)), - inline: false, + attributes: Vec::new(), const_nonmatching: true, combine_substructure: combine_substructure(|a, b, c| { encodable_substructure(a, b, c) diff --git a/src/libsyntax/ext/deriving/generic.rs b/src/libsyntax/ext/deriving/generic.rs index 673745b41e8..2b48cd58f50 100644 --- a/src/libsyntax/ext/deriving/generic.rs +++ b/src/libsyntax/ext/deriving/generic.rs @@ -229,8 +229,7 @@ pub struct MethodDef<'a> { /// Return type pub ret_ty: Ty<'a>, - /// Whether to mark this as #[inline] - pub inline: bool, + pub attributes: Vec, /// if the value of the nonmatching enums is independent of the /// actual enum variants, i.e. can use _ => .. match. @@ -612,23 +611,10 @@ impl<'a> MethodDef<'a> { let fn_decl = cx.fn_decl(args, ret_type); let body_block = cx.block_expr(body); - let attrs = if self.inline { - vec!( - cx - .attribute(trait_.span, - cx - .meta_word(trait_.span, - InternedString::new( - "inline"))) - ) - } else { - Vec::new() - }; - // Create the method. @ast::Method { ident: method_ident, - attrs: attrs, + attrs: self.attributes.clone(), generics: fn_generics, explicit_self: explicit_self, fn_style: ast::NormalFn, diff --git a/src/libsyntax/ext/deriving/hash.rs b/src/libsyntax/ext/deriving/hash.rs index 9e160b0e35d..d367ae61e0b 100644 --- a/src/libsyntax/ext/deriving/hash.rs +++ b/src/libsyntax/ext/deriving/hash.rs @@ -14,6 +14,7 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; pub fn expand_deriving_hash(cx: &mut ExtCtxt, span: Span, @@ -34,6 +35,8 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, LifetimeBounds::empty(), Path::new(vec!("std", "hash", "sip", "SipState"))) }; + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); let hash_trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -47,7 +50,7 @@ pub fn expand_deriving_hash(cx: &mut ExtCtxt, explicit_self: borrowed_explicit_self(), args: vec!(Ptr(~Literal(args), Borrowed(None, MutMutable))), ret_ty: nil_ty(), - inline: true, + attributes: attrs, const_nonmatching: false, combine_substructure: combine_substructure(|a, b, c| { hash_substructure(a, b, c) diff --git a/src/libsyntax/ext/deriving/primitive.rs b/src/libsyntax/ext/deriving/primitive.rs index e42a3c67e34..0a7aa591657 100644 --- a/src/libsyntax/ext/deriving/primitive.rs +++ b/src/libsyntax/ext/deriving/primitive.rs @@ -21,6 +21,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, mitem: @MetaItem, item: @Item, push: |@Item|) { + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -38,8 +40,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, None, vec!(~Self), true)), - // liable to cause code-bloat - inline: true, + // #[inline] liable to cause code-bloat + attributes: attrs.clone(), const_nonmatching: false, combine_substructure: combine_substructure(|c, s, sub| { cs_from("i64", c, s, sub) @@ -55,8 +57,8 @@ pub fn expand_deriving_from_primitive(cx: &mut ExtCtxt, None, vec!(~Self), true)), - // liable to cause code-bloat - inline: true, + // #[inline] liable to cause code-bloat + attributes: attrs, const_nonmatching: false, combine_substructure: combine_substructure(|c, s, sub| { cs_from("u64", c, s, sub) diff --git a/src/libsyntax/ext/deriving/rand.rs b/src/libsyntax/ext/deriving/rand.rs index 09c3abf42b8..23877dd29ea 100644 --- a/src/libsyntax/ext/deriving/rand.rs +++ b/src/libsyntax/ext/deriving/rand.rs @@ -41,7 +41,7 @@ pub fn expand_deriving_rand(cx: &mut ExtCtxt, Borrowed(None, ast::MutMutable)) ), ret_ty: Self, - inline: false, + attributes: Vec::new(), const_nonmatching: false, combine_substructure: combine_substructure(|a, b, c| { rand_substructure(a, b, c) diff --git a/src/libsyntax/ext/deriving/show.rs b/src/libsyntax/ext/deriving/show.rs index 7098d0dd6ef..b9725361538 100644 --- a/src/libsyntax/ext/deriving/show.rs +++ b/src/libsyntax/ext/deriving/show.rs @@ -42,7 +42,7 @@ pub fn expand_deriving_show(cx: &mut ExtCtxt, explicit_self: borrowed_explicit_self(), args: vec!(fmtr), ret_ty: Literal(Path::new(vec!("std", "fmt", "Result"))), - inline: false, + attributes: Vec::new(), const_nonmatching: false, combine_substructure: combine_substructure(|a, b, c| { show_substructure(a, b, c) diff --git a/src/libsyntax/ext/deriving/zero.rs b/src/libsyntax/ext/deriving/zero.rs index 0aeeabcaeab..449851dd3ea 100644 --- a/src/libsyntax/ext/deriving/zero.rs +++ b/src/libsyntax/ext/deriving/zero.rs @@ -13,12 +13,15 @@ use codemap::Span; use ext::base::ExtCtxt; use ext::build::AstBuilder; use ext::deriving::generic::*; +use parse::token::InternedString; pub fn expand_deriving_zero(cx: &mut ExtCtxt, span: Span, mitem: @MetaItem, item: @Item, push: |@Item|) { + let inline = cx.meta_word(span, InternedString::new("inline")); + let attrs = vec!(cx.attribute(span, inline)); let trait_def = TraitDef { span: span, attributes: Vec::new(), @@ -32,7 +35,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt, explicit_self: None, args: Vec::new(), ret_ty: Self, - inline: true, + attributes: attrs.clone(), const_nonmatching: false, combine_substructure: combine_substructure(|a, b, c| { zero_substructure(a, b, c) @@ -44,7 +47,7 @@ pub fn expand_deriving_zero(cx: &mut ExtCtxt, explicit_self: borrowed_explicit_self(), args: Vec::new(), ret_ty: Literal(Path::new(vec!("bool"))), - inline: true, + attributes: attrs, const_nonmatching: false, combine_substructure: combine_substructure(|cx, span, substr| { cs_and(|cx, span, _, _| cx.span_bug(span,