diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index d622965dac772..e33cf99102ccb 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1923,7 +1923,7 @@ impl Clean for ast::ViewItem_ { #[deriving(Clone, Encodable, Decodable)] pub enum ViewPath { - // use str = source; + // use source as str; SimpleImport(String, ImportSource), // use source::*; GlobImport(ImportSource), diff --git a/src/librustdoc/html/render.rs b/src/librustdoc/html/render.rs index 0ecb86d8bdd61..3b9c38d18fdbb 100644 --- a/src/librustdoc/html/render.rs +++ b/src/librustdoc/html/render.rs @@ -1386,6 +1386,8 @@ impl<'a> fmt::Show for Item<'a> { clean::TypedefItem(ref t) => item_typedef(fmt, self.item, t), clean::MacroItem(ref m) => item_macro(fmt, self.item, m), clean::PrimitiveItem(ref p) => item_primitive(fmt, self.item, p), + clean::StaticItem(ref i) => item_static(fmt, self.item, i), + clean::ConstantItem(ref c) => item_constant(fmt, self.item, c), _ => Ok(()) } } @@ -1411,13 +1413,6 @@ fn full_path(cx: &Context, item: &clean::Item) -> String { return s } -fn blank<'a>(s: Option<&'a str>) -> &'a str { - match s { - Some(s) => s, - None => "" - } -} - fn shorter<'a>(s: Option<&'a str>) -> &'a str { match s { Some(s) => match s.find_str("\n\n") { @@ -1528,66 +1523,18 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, id = short, name = name)); } - struct Initializer<'a>(&'a str, Item<'a>); - impl<'a> fmt::Show for Initializer<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let Initializer(s, item) = *self; - if s.len() == 0 { return Ok(()); } - try!(write!(f, " = ")); - if s.contains("\n") { - match item.href() { - Some(url) => { - write!(f, "[definition]", - url) - } - None => Ok(()), - } - } else { - write!(f, "{}", s.as_slice()) - } - } - } - match myitem.inner { - clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => { - try!(write!(w, " - - {}{}static {}{}: {}{} - {}  - - ", - ConciseStability(&myitem.stability), - VisSpace(myitem.visibility), - MutableSpace(s.mutability), - *myitem.name.as_ref().unwrap(), - s.type_, - Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }), - Markdown(blank(myitem.doc_value())))); - } - clean::ConstantItem(ref s) => { - try!(write!(w, " - - {}{}const {}: {}{} - {}  - - ", - ConciseStability(&myitem.stability), - VisSpace(myitem.visibility), - *myitem.name.as_ref().unwrap(), - s.type_, - Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }), - Markdown(blank(myitem.doc_value())))); - } - clean::ViewItemItem(ref item) => { match item.inner { clean::ExternCrate(ref name, ref src, _) => { - try!(write!(w, "extern crate {}", - name.as_slice())); match *src { - Some(ref src) => try!(write!(w, " = \"{}\"", - src.as_slice())), - None => {} + Some(ref src) => + try!(write!(w, "extern crate \"{}\" as {}", + src.as_slice(), + name.as_slice())), + None => + try!(write!(w, "extern crate {}", + name.as_slice())), } try!(write!(w, ";")); } @@ -1623,6 +1570,39 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context, write!(w, "") } +struct Initializer<'a>(&'a str); +impl<'a> fmt::Show for Initializer<'a> { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Initializer(s) = *self; + if s.len() == 0 { return Ok(()); } + try!(write!(f, " = ")); + write!(f, "{}", s.as_slice()) + } +} + +fn item_constant(w: &mut fmt::Formatter, it: &clean::Item, + c: &clean::Constant) -> fmt::Result { + try!(write!(w, "
{vis}const \
+                    {name}: {typ}{init}
", + vis = VisSpace(it.visibility), + name = it.name.as_ref().unwrap().as_slice(), + typ = c.type_, + init = Initializer(c.expr.as_slice()))); + document(w, it) +} + +fn item_static(w: &mut fmt::Formatter, it: &clean::Item, + s: &clean::Static) -> fmt::Result { + try!(write!(w, "
{vis}static {mutability}\
+                    {name}: {typ}{init}
", + vis = VisSpace(it.visibility), + mutability = MutableSpace(s.mutability), + name = it.name.as_ref().unwrap().as_slice(), + typ = s.type_, + init = Initializer(s.expr.as_slice()))); + document(w, it) +} + fn item_function(w: &mut fmt::Formatter, it: &clean::Item, f: &clean::Function) -> fmt::Result { try!(write!(w, "
{vis}{fn_style}fn \
diff --git a/src/librustdoc/html/static/main.css b/src/librustdoc/html/static/main.css
index b28da098a5783..4c01955039547 100644
--- a/src/librustdoc/html/static/main.css
+++ b/src/librustdoc/html/static/main.css
@@ -234,6 +234,7 @@ nav.sub {
 .content .highlighted.struct { background-color: #e7b1a0; }
 .content .highlighted.fn { background-color: #c6afb3; }
 .content .highlighted.method { background-color: #c6afb3; }
+.content .highlighted.tymethod { background-color: #c6afb3; }
 .content .highlighted.ffi { background-color: #c6afb3; }
 
 .docblock.short.nowrap {
@@ -348,6 +349,7 @@ p a:hover { text-decoration: underline; }
 .content span.struct, .content a.struct, .block a.current.struct { color: #e53700; }
 .content span.fn, .content a.fn, .block a.current.fn { color: #8c6067; }
 .content span.method, .content a.method, .block a.current.method { color: #8c6067; }
+.content span.tymethod, .content a.tymethod, .block a.current.tymethod { color: #8c6067; }
 .content span.ffi, .content a.ffi, .block a.current.ffi { color: #8c6067; }
 .content .fnname { color: #8c6067; }