]> git.lizzy.rs Git - rust.git/commitdiff
rustdoc: Inline static documentation across crates
authorAlex Crichton <alex@alexcrichton.com>
Fri, 6 Jun 2014 00:20:59 +0000 (17:20 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Sat, 7 Jun 2014 02:51:24 +0000 (19:51 -0700)
src/librustdoc/clean/inline.rs
src/librustdoc/html/format.rs
src/librustdoc/html/render.rs

index 9db9a0e7612a6908a5f9bba2a5a11d59366c968d..e9ea3a7b304e07c85612a485bd5faef921192b78 100644 (file)
@@ -88,6 +88,10 @@ fn try_inline_def(cx: &core::DocContext,
             record_extern_fqn(cx, did, clean::TypeModule);
             clean::ModuleItem(build_module(cx, tcx, did))
         }
+        ast::DefStatic(did, mtbl) => {
+            record_extern_fqn(cx, did, clean::TypeStatic);
+            clean::StaticItem(build_static(tcx, did, mtbl))
+        }
         _ => return None,
     };
     let fqn = csearch::get_item_path(tcx, did);
@@ -343,3 +347,13 @@ fn build_module(cx: &core::DocContext, tcx: &ty::ctxt,
         is_crate: false,
     }
 }
+
+fn build_static(tcx: &ty::ctxt,
+                did: ast::DefId,
+                mutable: bool) -> clean::Static {
+    clean::Static {
+        type_: ty::lookup_item_type(tcx, did).ty.clean(),
+        mutability: if mutable {clean::Mutable} else {clean::Immutable},
+        expr: "\n\n\n".to_string(), // trigger the "[definition]" links
+    }
+}
index 51d2a67d6cbf410f9148a1ca8d074254aa4590d6..1706f00b70a6fb6f50f43ae8d43e004d1c5990d8 100644 (file)
@@ -35,6 +35,8 @@
 pub struct FnStyleSpace(pub ast::FnStyle);
 /// Wrapper struct for properly emitting a method declaration.
 pub struct Method<'a>(pub &'a clean::SelfTy, pub &'a clean::FnDecl);
+/// Similar to VisSpace, but used for mutability
+pub struct MutableSpace(pub clean::Mutability);
 
 impl VisSpace {
     pub fn get(&self) -> Option<ast::Visibility> {
@@ -438,24 +440,14 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             clean::Unique(ref t) => write!(f, "~{}", **t),
             clean::Managed(ref t) => write!(f, "@{}", **t),
             clean::RawPointer(m, ref t) => {
-                write!(f, "*{}{}",
-                       match m {
-                           clean::Mutable => "mut ",
-                           clean::Immutable => "",
-                       }, **t)
+                write!(f, "*{}{}", MutableSpace(m), **t)
             }
             clean::BorrowedRef{ lifetime: ref l, mutability, type_: ref ty} => {
                 let lt = match *l {
                     Some(ref l) => format!("{} ", *l),
                     _ => "".to_string(),
                 };
-                write!(f, "&amp;{}{}{}",
-                       lt,
-                       match mutability {
-                           clean::Mutable => "mut ",
-                           clean::Immutable => "",
-                       },
-                       **ty)
+                write!(f, "&amp;{}{}{}", lt, MutableSpace(mutability), **ty)
             }
         }
     }
@@ -494,17 +486,13 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
             clean::SelfStatic => {},
             clean::SelfValue => args.push_str("self"),
             clean::SelfOwned => args.push_str("~self"),
-            clean::SelfBorrowed(Some(ref lt), clean::Immutable) => {
-                args.push_str(format!("&amp;{} self", *lt).as_slice());
-            }
-            clean::SelfBorrowed(Some(ref lt), clean::Mutable) => {
-                args.push_str(format!("&amp;{} mut self", *lt).as_slice());
-            }
-            clean::SelfBorrowed(None, clean::Mutable) => {
-                args.push_str("&amp;mut self");
+            clean::SelfBorrowed(Some(ref lt), mtbl) => {
+                args.push_str(format!("&amp;{} {}self", *lt,
+                                      MutableSpace(mtbl)).as_slice());
             }
-            clean::SelfBorrowed(None, clean::Immutable) => {
-                args.push_str("&amp;self");
+            clean::SelfBorrowed(None, mtbl) => {
+                args.push_str(format!("&amp;{}self",
+                                      MutableSpace(mtbl)).as_slice());
             }
         }
         for (i, input) in d.inputs.values.iter().enumerate() {
@@ -605,3 +593,12 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         }
     }
 }
+
+impl fmt::Show for MutableSpace {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        match *self {
+            MutableSpace(clean::Immutable) => Ok(()),
+            MutableSpace(clean::Mutable) => write!(f, "mut "),
+        }
+    }
+}
index 4ef3297912f9efc8e18e8445134402ca94911f8d..086232104e36d5f78ef783be8f898cc72b1e7c2a 100644 (file)
@@ -51,7 +51,7 @@
 use clean;
 use doctree;
 use fold::DocFolder;
-use html::format::{VisSpace, Method, FnStyleSpace};
+use html::format::{VisSpace, Method, FnStyleSpace, MutableSpace};
 use html::highlight;
 use html::item_type::{ItemType, shortty};
 use html::item_type;
@@ -1441,11 +1441,12 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
 
                 try!(write!(w, "
                     <tr>
-                        <td><code>{}static {}: {}</code>{}</td>
+                        <td><code>{}static {}{}: {}</code>{}</td>
                         <td class='docblock'>{}&nbsp;</td>
                     </tr>
                 ",
                 VisSpace(myitem.visibility),
+                MutableSpace(s.mutability),
                 *myitem.name.get_ref(),
                 s.type_,
                 Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),