Skip to content

Commit 593af62

Browse files
author
Jakub Bukaj
committed
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: ![Constant listing](https://i.imgur.com/L4ZTOCN.png) ![Constant page](https://i.imgur.com/RcjZfCv.png)
2 parents e9fcfe6 + 55af4af commit 593af62

File tree

3 files changed

+45
-63
lines changed

3 files changed

+45
-63
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1923,7 +1923,7 @@ impl Clean<ViewItemInner> for ast::ViewItem_ {
19231923

19241924
#[deriving(Clone, Encodable, Decodable)]
19251925
pub enum ViewPath {
1926-
// use str = source;
1926+
// use source as str;
19271927
SimpleImport(String, ImportSource),
19281928
// use source::*;
19291929
GlobImport(ImportSource),

src/librustdoc/html/render.rs

Lines changed: 42 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,8 @@ impl<'a> fmt::Show for Item<'a> {
14281428
clean::TypedefItem(ref t) => item_typedef(fmt, self.item, t),
14291429
clean::MacroItem(ref m) => item_macro(fmt, self.item, m),
14301430
clean::PrimitiveItem(ref p) => item_primitive(fmt, self.item, p),
1431+
clean::StaticItem(ref i) => item_static(fmt, self.item, i),
1432+
clean::ConstantItem(ref c) => item_constant(fmt, self.item, c),
14311433
_ => Ok(())
14321434
}
14331435
}
@@ -1453,13 +1455,6 @@ fn full_path(cx: &Context, item: &clean::Item) -> String {
14531455
return s
14541456
}
14551457

1456-
fn blank<'a>(s: Option<&'a str>) -> &'a str {
1457-
match s {
1458-
Some(s) => s,
1459-
None => ""
1460-
}
1461-
}
1462-
14631458
fn shorter<'a>(s: Option<&'a str>) -> &'a str {
14641459
match s {
14651460
Some(s) => match s.find_str("\n\n") {
@@ -1570,66 +1565,18 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
15701565
id = short, name = name));
15711566
}
15721567

1573-
struct Initializer<'a>(&'a str, Item<'a>);
1574-
impl<'a> fmt::Show for Initializer<'a> {
1575-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1576-
let Initializer(s, item) = *self;
1577-
if s.len() == 0 { return Ok(()); }
1578-
try!(write!(f, "<code> = </code>"));
1579-
if s.contains("\n") {
1580-
match item.href() {
1581-
Some(url) => {
1582-
write!(f, "<a href='{}'>[definition]</a>",
1583-
url)
1584-
}
1585-
None => Ok(()),
1586-
}
1587-
} else {
1588-
write!(f, "<code>{}</code>", s.as_slice())
1589-
}
1590-
}
1591-
}
1592-
15931568
match myitem.inner {
1594-
clean::StaticItem(ref s) | clean::ForeignStaticItem(ref s) => {
1595-
try!(write!(w, "
1596-
<tr>
1597-
<td>{}<code>{}static {}{}: {}</code>{}</td>
1598-
<td class='docblock'>{}&nbsp;</td>
1599-
</tr>
1600-
",
1601-
ConciseStability(&myitem.stability),
1602-
VisSpace(myitem.visibility),
1603-
MutableSpace(s.mutability),
1604-
*myitem.name.as_ref().unwrap(),
1605-
s.type_,
1606-
Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),
1607-
Markdown(blank(myitem.doc_value()))));
1608-
}
1609-
clean::ConstantItem(ref s) => {
1610-
try!(write!(w, "
1611-
<tr>
1612-
<td>{}<code>{}const {}: {}</code>{}</td>
1613-
<td class='docblock'>{}&nbsp;</td>
1614-
</tr>
1615-
",
1616-
ConciseStability(&myitem.stability),
1617-
VisSpace(myitem.visibility),
1618-
*myitem.name.as_ref().unwrap(),
1619-
s.type_,
1620-
Initializer(s.expr.as_slice(), Item { cx: cx, item: myitem }),
1621-
Markdown(blank(myitem.doc_value()))));
1622-
}
1623-
16241569
clean::ViewItemItem(ref item) => {
16251570
match item.inner {
16261571
clean::ExternCrate(ref name, ref src, _) => {
1627-
try!(write!(w, "<tr><td><code>extern crate {}",
1628-
name.as_slice()));
16291572
match *src {
1630-
Some(ref src) => try!(write!(w, " = \"{}\"",
1631-
src.as_slice())),
1632-
None => {}
1573+
Some(ref src) =>
1574+
try!(write!(w, "<tr><td><code>extern crate \"{}\" as {}",
1575+
src.as_slice(),
1576+
name.as_slice())),
1577+
None =>
1578+
try!(write!(w, "<tr><td><code>extern crate {}",
1579+
name.as_slice())),
16331580
}
16341581
try!(write!(w, ";</code></td></tr>"));
16351582
}
@@ -1665,6 +1612,39 @@ fn item_module(w: &mut fmt::Formatter, cx: &Context,
16651612
write!(w, "</table>")
16661613
}
16671614

1615+
struct Initializer<'a>(&'a str);
1616+
impl<'a> fmt::Show for Initializer<'a> {
1617+
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
1618+
let Initializer(s) = *self;
1619+
if s.len() == 0 { return Ok(()); }
1620+
try!(write!(f, "<code> = </code>"));
1621+
write!(f, "<code>{}</code>", s.as_slice())
1622+
}
1623+
}
1624+
1625+
fn item_constant(w: &mut fmt::Formatter, it: &clean::Item,
1626+
c: &clean::Constant) -> fmt::Result {
1627+
try!(write!(w, "<pre class='rust const'>{vis}const \
1628+
{name}: {typ}{init}</pre>",
1629+
vis = VisSpace(it.visibility),
1630+
name = it.name.as_ref().unwrap().as_slice(),
1631+
typ = c.type_,
1632+
init = Initializer(c.expr.as_slice())));
1633+
document(w, it)
1634+
}
1635+
1636+
fn item_static(w: &mut fmt::Formatter, it: &clean::Item,
1637+
s: &clean::Static) -> fmt::Result {
1638+
try!(write!(w, "<pre class='rust static'>{vis}static {mutability}\
1639+
{name}: {typ}{init}</pre>",
1640+
vis = VisSpace(it.visibility),
1641+
mutability = MutableSpace(s.mutability),
1642+
name = it.name.as_ref().unwrap().as_slice(),
1643+
typ = s.type_,
1644+
init = Initializer(s.expr.as_slice())));
1645+
document(w, it)
1646+
}
1647+
16681648
fn item_function(w: &mut fmt::Formatter, it: &clean::Item,
16691649
f: &clean::Function) -> fmt::Result {
16701650
try!(write!(w, "<pre class='rust fn'>{vis}{fn_style}fn \

src/librustdoc/html/static/main.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ nav.sub {
234234
.content .highlighted.struct { background-color: #e7b1a0; }
235235
.content .highlighted.fn { background-color: #c6afb3; }
236236
.content .highlighted.method { background-color: #c6afb3; }
237+
.content .highlighted.tymethod { background-color: #c6afb3; }
237238
.content .highlighted.ffi { background-color: #c6afb3; }
238239

239240
.docblock.short.nowrap {
@@ -348,6 +349,7 @@ p a:hover { text-decoration: underline; }
348349
.content span.struct, .content a.struct, .block a.current.struct { color: #e53700; }
349350
.content span.fn, .content a.fn, .block a.current.fn { color: #8c6067; }
350351
.content span.method, .content a.method, .block a.current.method { color: #8c6067; }
352+
.content span.tymethod, .content a.tymethod, .block a.current.tymethod { color: #8c6067; }
351353
.content span.ffi, .content a.ffi, .block a.current.ffi { color: #8c6067; }
352354
.content .fnname { color: #8c6067; }
353355

0 commit comments

Comments
 (0)