Skip to content

Commit d130d87

Browse files
committed
auto merge of #12961 : cmr/rust/rustdoc-impls, r=alexcrichton
Rendered form available at http://docs.octayn.net/doc/ This moves derived impls to the bottom of the list, separate from the rest, and collapses default methods that aren't overridden into an expandible accordion.
2 parents de44732 + 1f937fa commit d130d87

File tree

3 files changed

+65
-32
lines changed

3 files changed

+65
-32
lines changed

src/librustdoc/clean.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,18 @@ pub enum ItemEnum {
174174
StaticItem(Static),
175175
TraitItem(Trait),
176176
ImplItem(Impl),
177+
/// `use` and `extern crate`
177178
ViewItemItem(ViewItem),
179+
/// A method signature only. Used for required methods in traits (ie,
180+
/// non-default-methods).
178181
TyMethodItem(TyMethod),
182+
/// A method with a body.
179183
MethodItem(Method),
180184
StructFieldItem(StructField),
181185
VariantItem(Variant),
186+
/// `fn`s from an extern block
182187
ForeignFunctionItem(Function),
188+
/// `static`s from an extern block
183189
ForeignStaticItem(Static),
184190
MacroItem(Macro),
185191
}
@@ -1014,11 +1020,23 @@ pub struct Impl {
10141020
generics: Generics,
10151021
trait_: Option<Type>,
10161022
for_: Type,
1017-
methods: Vec<Item> ,
1023+
methods: Vec<Item>,
1024+
derived: bool,
10181025
}
10191026

10201027
impl Clean<Item> for doctree::Impl {
10211028
fn clean(&self) -> Item {
1029+
let mut derived = false;
1030+
for attr in self.attrs.iter() {
1031+
match attr.node.value.node {
1032+
ast::MetaWord(ref s) => {
1033+
if s.get() == "automatically_derived" {
1034+
derived = true;
1035+
}
1036+
}
1037+
_ => {}
1038+
}
1039+
}
10221040
Item {
10231041
name: None,
10241042
attrs: self.attrs.clean(),
@@ -1030,6 +1048,7 @@ impl Clean<Item> for doctree::Impl {
10301048
trait_: self.trait_.clean(),
10311049
for_: self.for_.clean(),
10321050
methods: self.methods.clean(),
1051+
derived: derived,
10331052
}),
10341053
}
10351054
}

src/librustdoc/html/layout.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -29,53 +29,53 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
2929
-> fmt::Result
3030
{
3131
write!(dst,
32-
"<!DOCTYPE html>
33-
<html lang=\"en\">
32+
r##"<!DOCTYPE html>
33+
<html lang="en">
3434
<head>
35-
<meta charset=\"utf-8\" />
35+
<meta charset="utf-8" />
3636
<title>{title}</title>
3737
3838
<link href='http://fonts.googleapis.com/css?family=Oswald:700|Inconsolata:400,700'
3939
rel='stylesheet' type='text/css'>
40-
<link rel=\"stylesheet\" type=\"text/css\" href=\"{root_path}main.css\">
40+
<link rel="stylesheet" type="text/css" href="{root_path}main.css">
4141
42-
{favicon, select, none{} other{<link rel=\"shortcut icon\" href=\"#\" />}}
42+
{favicon, select, none{} other{<link rel="shortcut icon" href="\#" />}}
4343
</head>
4444
<body>
4545
<!--[if lte IE 8]>
46-
<div class=\"warning\">
46+
<div class="warning">
4747
This old browser is unsupported and will most likely display funky
4848
things.
4949
</div>
5050
<![endif]-->
5151
52-
<section class=\"sidebar\">
52+
<section class="sidebar">
5353
{logo, select, none{} other{
54-
<a href='{root_path}{krate}/index.html'><img src='#' alt=''/></a>
54+
<a href='{root_path}{krate}/index.html'><img src='\#' alt=''/></a>
5555
}}
5656
5757
{sidebar}
5858
</section>
5959
60-
<nav class=\"sub\">
61-
<form class=\"search-form js-only\">
62-
<button class=\"do-search\">Search</button>
63-
<div class=\"search-container\">
64-
<input class=\"search-input\" name=\"search\"
65-
autocomplete=\"off\"
66-
placeholder=\"Search documentation...\"
67-
type=\"search\" />
60+
<nav class="sub">
61+
<form class="search-form js-only">
62+
<button class="do-search">Search</button>
63+
<div class="search-container">
64+
<input class="search-input" name="search"
65+
autocomplete="off"
66+
placeholder="Search documentation..."
67+
type="search" />
6868
</div>
6969
</form>
7070
</nav>
7171
72-
<section id='main' class=\"content {ty}\">{content}</section>
73-
<section id='search' class=\"content hidden\"></section>
72+
<section id='main' class="content {ty}">{content}</section>
73+
<section id='search' class="content hidden"></section>
7474
75-
<section class=\"footer\"></section>
75+
<section class="footer"></section>
7676
77-
<div id=\"help\" class=\"hidden\">
78-
<div class=\"shortcuts\">
77+
<div id="help" class="hidden">
78+
<div class="shortcuts">
7979
<h1>Keyboard shortcuts</h1>
8080
<dl>
8181
<dt>?</dt>
@@ -86,11 +86,11 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
8686
<dd>Move up in search results</dd>
8787
<dt>&darr;</dt>
8888
<dd>Move down in search results</dd>
89-
<dt>&\\#9166;</dt>
89+
<dt>&\#9166;</dt>
9090
<dd>Go to active search result</dd>
9191
</dl>
9292
</div>
93-
<div class=\"infos\">
93+
<div class="infos">
9494
<h1>Search tricks</h1>
9595
<p>
9696
Prefix searches with a type followed by a colon (e.g.
@@ -106,15 +106,15 @@ pub fn render<T: fmt::Show, S: fmt::Show>(
106106
</div>
107107
108108
<script>
109-
var rootPath = \"{root_path}\";
110-
var currentCrate = \"{krate}\";
109+
var rootPath = "{root_path}";
110+
var currentCrate = "{krate}";
111111
</script>
112-
<script src=\"{root_path}jquery.js\"></script>
113-
<script src=\"{root_path}main.js\"></script>
114-
<script async src=\"{root_path}search-index.js\"></script>
112+
<script src="{root_path}jquery.js"></script>
113+
<script src="{root_path}main.js"></script>
114+
<script async src="{root_path}search-index.js"></script>
115115
</body>
116116
</html>
117-
",
117+
"##,
118118
content = *t,
119119
root_path = page.root_path,
120120
ty = page.ty,

src/librustdoc/html/render.rs

+16-2
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,22 @@ fn render_methods(w: &mut Writer, it: &clean::Item) -> fmt::Result {
15171517
if traits.len() > 0 {
15181518
try!(write!(w, "<h2 id='implementations'>Trait \
15191519
Implementations</h2>"));
1520-
for &(ref i, ref dox) in traits.move_iter() {
1521-
try!(render_impl(w, i, dox));
1520+
let mut any_derived = false;
1521+
for & &(ref i, ref dox) in traits.iter() {
1522+
if !i.derived {
1523+
try!(render_impl(w, i, dox));
1524+
} else {
1525+
any_derived = true;
1526+
}
1527+
}
1528+
if any_derived {
1529+
try!(write!(w, "<h3 id='derived_implementations'>Derived Implementations \
1530+
</h3>"));
1531+
for &(ref i, ref dox) in traits.move_iter() {
1532+
if i.derived {
1533+
try!(render_impl(w, i, dox));
1534+
}
1535+
}
15221536
}
15231537
}
15241538
}

0 commit comments

Comments
 (0)