Skip to content

Miscellaneous rustdoc fixes #19234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 23, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1923,7 +1923,7 @@ impl Clean<ViewItemInner> for ast::ViewItem_ {

#[deriving(Clone, Encodable, Decodable)]
pub enum ViewPath {
// use str = source;
// use source as str;
SimpleImport(String, ImportSource),
// use source::*;
GlobImport(ImportSource),
Expand Down
104 changes: 42 additions & 62 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
}
Expand All @@ -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") {
Expand Down Expand Up @@ -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, "<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 {
clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
try!(write!(w, "
<tr>
<td>{}<code>{}static {}{}: {}</code>{}</td>
<td class='docblock'>{}&nbsp;</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'>{}&nbsp;</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) => {
match item.inner {
clean::ExternCrate(ref name, ref src, _) => {
try!(write!(w, "<tr><td><code>extern crate {}",
name.as_slice()));
match *src {
Some(ref src) => try!(write!(w, " = \"{}\"",
src.as_slice())),
None => {}
Some(ref src) =>
try!(write!(w, "<tr><td><code>extern crate \"{}\" as {}",
src.as_slice(),
name.as_slice())),
None =>
try!(write!(w, "<tr><td><code>extern crate {}",
name.as_slice())),
}
try!(write!(w, ";</code></td></tr>"));
}
Expand Down Expand Up @@ -1623,6 +1570,39 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
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,
f: &clean::Function) -> fmt::Result {
try!(write!(w, "<pre class='rust fn'>{vis}{fn_style}fn \
Expand Down
2 changes: 2 additions & 0 deletions src/librustdoc/html/static/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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; }

Expand Down