rollup merge of #19234: P1start/rustdoc-misc
This PR: - makes rustdoc colour trait methods like other functions in search results; - makes rustdoc display `extern crate` statements with the new `as` syntax instead of the old `=` syntax; - changes rustdoc to list constants and statics in a way that is more similar to functions and modules and show their full definition and documentation on their own page, fixing #19046:  
This commit is contained in:
commit
593af6213f
3 changed files with 45 additions and 63 deletions
|
@ -1923,7 +1923,7 @@ impl Clean<ViewItemInner> for ast::ViewItem_ {
|
||||||
|
|
||||||
#[deriving(Clone, Encodable, Decodable)]
|
#[deriving(Clone, Encodable, Decodable)]
|
||||||
pub enum ViewPath {
|
pub enum ViewPath {
|
||||||
// use str = source;
|
// use source as str;
|
||||||
SimpleImport(String, ImportSource),
|
SimpleImport(String, ImportSource),
|
||||||
// use source::*;
|
// use source::*;
|
||||||
GlobImport(ImportSource),
|
GlobImport(ImportSource),
|
||||||
|
|
|
@ -1428,6 +1428,8 @@ impl<'a> fmt::Show for Item<'a> {
|
||||||
clean::TypedefItem(ref t) => item_typedef(fmt, self.item, t),
|
clean::TypedefItem(ref t) => item_typedef(fmt, self.item, t),
|
||||||
clean::MacroItem(ref m) => item_macro(fmt, self.item, m),
|
clean::MacroItem(ref m) => item_macro(fmt, self.item, m),
|
||||||
clean::PrimitiveItem(ref p) => item_primitive(fmt, self.item, p),
|
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(())
|
_ => Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1453,13 +1455,6 @@ fn full_path(cx: &Context, item: &clean::Item) -> String {
|
||||||
return s
|
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 {
|
fn shorter<'a>(s: Option<&'a str>) -> &'a str {
|
||||||
match s {
|
match s {
|
||||||
Some(s) => match s.find_str("\n\n") {
|
Some(s) => match s.find_str("\n\n") {
|
||||||
|
@ -1570,66 +1565,18 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||||
id = short, name = name));
|
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, "<code> = </code>"));
|
|
||||||
if s.contains("\n") {
|
|
||||||
match item.href() {
|
|
||||||
Some(url) => {
|
|
||||||
write!(f, "<a href='{}'>[definition]</a>",
|
|
||||||
url)
|
|
||||||
}
|
|
||||||
None => Ok(()),
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
write!(f, "<code>{}</code>", s.as_slice())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
match myitem.inner {
|
match myitem.inner {
|
||||||
clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
|
|
||||||
try!(write!(w, "
|
|
||||||
<tr>
|
|
||||||
<td>{}<code>{}static {}{}: {}</code>{}</td>
|
|
||||||
<td class='docblock'>{} </td>
|
|
||||||
</tr>
|
|
||||||
",
|
|
||||||
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, "
|
|
||||||
<tr>
|
|
||||||
<td>{}<code>{}const {}: {}</code>{}</td>
|
|
||||||
<td class='docblock'>{} </td>
|
|
||||||
</tr>
|
|
||||||
",
|
|
||||||
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) => {
|
clean::ViewItemItem(ref item) => {
|
||||||
match item.inner {
|
match item.inner {
|
||||||
clean::ExternCrate(ref name, ref src, _) => {
|
clean::ExternCrate(ref name, ref src, _) => {
|
||||||
try!(write!(w, "<tr><td><code>extern crate {}",
|
|
||||||
name.as_slice()));
|
|
||||||
match *src {
|
match *src {
|
||||||
Some(ref src) => try!(write!(w, " = \"{}\"",
|
Some(ref src) =>
|
||||||
src.as_slice())),
|
try!(write!(w, "<tr><td><code>extern crate \"{}\" as {}",
|
||||||
None => {}
|
src.as_slice(),
|
||||||
|
name.as_slice())),
|
||||||
|
None =>
|
||||||
|
try!(write!(w, "<tr><td><code>extern crate {}",
|
||||||
|
name.as_slice())),
|
||||||
}
|
}
|
||||||
try!(write!(w, ";</code></td></tr>"));
|
try!(write!(w, ";</code></td></tr>"));
|
||||||
}
|
}
|
||||||
|
@ -1665,6 +1612,39 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
|
||||||
write!(w, "</table>")
|
write!(w, "</table>")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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, "<code> = </code>"));
|
||||||
|
write!(f, "<code>{}</code>", s.as_slice())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn item_constant(w: &mut fmt::Formatter, it: &clean::Item,
|
||||||
|
c: &clean::Constant) -> fmt::Result {
|
||||||
|
try!(write!(w, "<pre class='rust const'>{vis}const \
|
||||||
|
{name}: {typ}{init}</pre>",
|
||||||
|
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, "<pre class='rust static'>{vis}static {mutability}\
|
||||||
|
{name}: {typ}{init}</pre>",
|
||||||
|
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,
|
fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
|
||||||
f: &clean::Function) -> fmt::Result {
|
f: &clean::Function) -> fmt::Result {
|
||||||
try!(write!(w, "<pre class='rust fn'>{vis}{fn_style}fn \
|
try!(write!(w, "<pre class='rust fn'>{vis}{fn_style}fn \
|
||||||
|
|
|
@ -234,6 +234,7 @@ nav.sub {
|
||||||
.content .highlighted.struct { background-color: #e7b1a0; }
|
.content .highlighted.struct { background-color: #e7b1a0; }
|
||||||
.content .highlighted.fn { background-color: #c6afb3; }
|
.content .highlighted.fn { background-color: #c6afb3; }
|
||||||
.content .highlighted.method { background-color: #c6afb3; }
|
.content .highlighted.method { background-color: #c6afb3; }
|
||||||
|
.content .highlighted.tymethod { background-color: #c6afb3; }
|
||||||
.content .highlighted.ffi { background-color: #c6afb3; }
|
.content .highlighted.ffi { background-color: #c6afb3; }
|
||||||
|
|
||||||
.docblock.short.nowrap {
|
.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.struct, .content a.struct, .block a.current.struct { color: #e53700; }
|
||||||
.content span.fn, .content a.fn, .block a.current.fn { color: #8c6067; }
|
.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.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 span.ffi, .content a.ffi, .block a.current.ffi { color: #8c6067; }
|
||||||
.content .fnname { color: #8c6067; }
|
.content .fnname { color: #8c6067; }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue