]> git.lizzy.rs Git - rust.git/commitdiff
Honor hidden doc attribute of derivable trait methods
authorEdward Wang <edward.yu.wang@gmail.com>
Wed, 23 Apr 2014 14:43:45 +0000 (22:43 +0800)
committerEdward Wang <edward.yu.wang@gmail.com>
Wed, 23 Apr 2014 14:43:45 +0000 (22:43 +0800)
Closes #13698

14 files changed:
src/libsyntax/ext/deriving/clone.rs
src/libsyntax/ext/deriving/cmp/eq.rs
src/libsyntax/ext/deriving/cmp/ord.rs
src/libsyntax/ext/deriving/cmp/totaleq.rs
src/libsyntax/ext/deriving/cmp/totalord.rs
src/libsyntax/ext/deriving/decodable.rs
src/libsyntax/ext/deriving/default.rs
src/libsyntax/ext/deriving/encodable.rs
src/libsyntax/ext/deriving/generic.rs
src/libsyntax/ext/deriving/hash.rs
src/libsyntax/ext/deriving/primitive.rs
src/libsyntax/ext/deriving/rand.rs
src/libsyntax/ext/deriving/show.rs
src/libsyntax/ext/deriving/zero.rs

index 367accb4b19d863016b15245b1effcf5b6eb352e..6db9954820678d942475097346953f3eb0ce40d4 100644 (file)
 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: |c, s, sub| cs_clone("Clone", c, s, sub)
             }
index 975b8885de7348deee1541467544970ef83a3f4b..8a877a2a7a4a35b081836018e5aace6baa9867cb 100644 (file)
@@ -13,6 +13,7 @@
 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,18 +32,20 @@ fn cs_ne(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @Expr {
     }
 
     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: $f
             }
-        }
+        } }
     );
 
     let trait_def = TraitDef {
index 5605c0b61071b78563dea401f33ab2e426cea325..2b2a490e5a403932f493f1ec4049cb94c20276e6 100644 (file)
@@ -14,6 +14,7 @@
 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,18 +22,20 @@ 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: |cx, span, substr| cs_op($op, $equal, cx, span, substr)
             }
-        }
+        } }
     );
 
     let trait_def = TraitDef {
index 33512b3df5ee563044cfb6644d0d07466127ec53..24e0fc73f2a3d1234e322a2c116013725d9ab1a1 100644 (file)
@@ -13,6 +13,7 @@
 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 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @E
                        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 @@ fn cs_total_eq_assert(cx: &mut ExtCtxt, span: Span, substr: &Substructure) -> @E
                 explicit_self: borrowed_explicit_self(),
                 args: vec!(),
                 ret_ty: nil_ty(),
-                inline: true,
+                attributes: attrs,
                 const_nonmatching: true,
                 combine_substructure: cs_total_eq_assert
             }
index a584f8abe05ef78b6a7df196478fc6c9b6ba90c4..c2e52f7ef7701a8a054112aab68e2c51448b2718 100644 (file)
@@ -14,6 +14,7 @@
 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: cs_cmp
             }
index 35a1eb0bb8381206a23b0d166044d5c7fe77adfe..56fde41635f18befd0c29587f03121448900dd5d 100644 (file)
@@ -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: decodable_substructure,
             })
index 94675f91e9d6c684d0d5ddf346d332a7b3443eb3..e89e25dd26c8337eeb0d7b62688bcd0c9d34b60b 100644 (file)
 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: default_substructure
             })
index 806560f6826adbda053b77e0a34e9fb6a772a194..8fdb994ecdd80ba2142e8cf062abc35395565fe6 100644 (file)
@@ -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: encodable_substructure,
             })
index 914451fb4024e9a71b8ad770c17f334334d763f6..f5bc3319da163391ef758d4fc8ba2b07793df7e0 100644 (file)
@@ -227,8 +227,7 @@ pub struct MethodDef<'a> {
     /// Return type
     pub ret_ty: Ty<'a>,
 
-    /// Whether to mark this as #[inline]
-    pub inline: bool,
+    pub attributes: Vec<ast::Attribute>,
 
     /// if the value of the nonmatching enums is independent of the
     /// actual enum variants, i.e. can use _ => .. match.
@@ -604,23 +603,10 @@ fn create_method(&self,
         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,
index d22027d203facff771de33f17bc4489945a3a876..c6f0900d27bd73a90d8d6e76fa6f04b9af86e3c0 100644 (file)
@@ -14,6 +14,7 @@
 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: hash_substructure
             }
index 267a12fdff90d017d588ac1928605d6bf7008545..90b011d24e3eacc3b29528272f7ad8d508203f95 100644 (file)
@@ -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: |c, s, sub| cs_from("i64", c, s, sub),
             },
@@ -53,8 +55,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: |c, s, sub| cs_from("u64", c, s, sub),
             })
index e81aa55d10d32c2b8ed1a4a4239f89702913c7bd..597e0959de2df8a4a7ebeeb62580f2c2b7ce6146 100644 (file)
@@ -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: rand_substructure
             }
index 067958e4bdec7111076577620336c5afd58cd814..153374fbc1630d60a8547fdf62e0fc2700eb5f51 100644 (file)
@@ -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: show_substructure
             }
index 10692bd7f93f6a399786bfbccce84ec538421421..cbb113f15f707169479f425690151da9a1296c31 100644 (file)
 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: zero_substructure
             },
@@ -42,7 +45,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: |cx, span, substr| {
                     cs_and(|cx, span, _, _| cx.span_bug(span,