Skip to content

Commit

Permalink
Review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Aug 15, 2016
1 parent 525b77e commit 6765f7e
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 30 deletions.
65 changes: 37 additions & 28 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2036,14 +2036,18 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean::Item)
-> fmt::Result {
let name = m.name.as_ref().unwrap();
let id = derive_id(format!("{}.{}", item_type(m), name));
write!(w, "<h3 id='{id}' class='method stab {stab}'><code>",
let item_type = item_type(m);
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h3 id='{id}' class='method stab {stab}'>\
<span id='{ns_id}' class='invisible'><code>",
id = id,
stab = m.stability_class())?;
stab = m.stability_class(),
ns_id = ns_id)?;
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)))?;
write!(w, "</code>")?;
render_stability_since(w, m, t)?;
write!(w, "</h3>")?;
write!(w, "</span></h3>")?;
document(w, cx, m)?;
Ok(())
}
Expand Down Expand Up @@ -2283,9 +2287,9 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "<h2 class='fields'>Fields</h2>")?;
for (field, ty) in fields {
write!(w, "<span id='{item_type}.{name}' class='{item_type}'>
<a id='{name}.{name_space}'>
<span id='{name}.{name_space}' class='invisible'>
<code>{name}: {ty}</code>
</a></span><span class='stab {stab}'></span>",
</span></span><span class='stab {stab}'></span>",
item_type = ItemType::StructField,
name_space = ItemType::StructField.name_space(),
stab = field.stability_class(),
Expand Down Expand Up @@ -2357,7 +2361,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, "<h2 class='variants'>Variants</h2>\n")?;
for variant in &e.variants {
write!(w, "<span id='{item_type}.{name}' class='variant'>\
<a id='{name}.{name_space}'><code>{name}",
<span id='{name}.{name_space}' class='invisible'><code>{name}",
item_type = ItemType::Variant,
name_space = ItemType::Variant.name_space(),
name = variant.name.as_ref().unwrap())?;
Expand All @@ -2373,7 +2377,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
write!(w, ")")?;
}
}
write!(w, "</code></a></span>")?;
write!(w, "</code></span></span>")?;
document(w, cx, variant)?;

use clean::{Variant, StructVariant};
Expand All @@ -2385,8 +2389,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
if let StructFieldItem(ref ty) = field.inner {
write!(w, "<tr><td \
id='variant.{v}.field.{f}'>\
<a id='{v}.{vns}.{f}.{fns}'>\
<code>{f}:&nbsp;{t}</code></a></td><td>",
<span id='{v}.{vns}.{f}.{fns}' class='invisible'>\
<code>{f}:&nbsp;{t}</code></span></td><td>",
v = variant.name.as_ref().unwrap(),
f = field.name.as_ref().unwrap(),
vns = ItemType::Variant.name_space(),
Expand Down Expand Up @@ -2606,10 +2610,10 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
}
}

fn doctraititem(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
link: AssocItemLink, render_static: bool,
is_default_item: bool, outer_version: Option<&str>,
trait_: Option<&clean::Trait>) -> fmt::Result {
fn doc_impl_item(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
link: AssocItemLink, render_static: bool,
is_default_item: bool, outer_version: Option<&str>,
trait_: Option<&clean::Trait>) -> fmt::Result {
let item_type = item_type(item);
let name = item.name.as_ref().unwrap();

Expand All @@ -2624,42 +2628,47 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
// Only render when the method is not static or we allow static methods
if !is_static || render_static {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
write!(w, "<a id='{}.{}'>", name, item_type.name_space())?;
write!(w, "<span id='{}' class='invisible'>", ns_id)?;
write!(w, "<code>")?;
render_assoc_item(w, item, link.anchor(&id))?;
write!(w, "</code>")?;
render_stability_since_raw(w, item.stable_since(), outer_version)?;
write!(w, "</a></h4>\n")?;
write!(w, "</span></h4>\n")?;
}
}
clean::TypedefItem(ref tydef, _) => {
let id = derive_id(format!("{}.{}", ItemType::AssociatedType, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id))?;
write!(w, "</code></a></h4>\n")?;
write!(w, "</code></span></h4>\n")?;
}
clean::AssociatedConstItem(ref ty, ref default) => {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
write!(w, "</code></a></h4>\n")?;
write!(w, "</code></span></h4>\n")?;
}
clean::ConstantItem(ref c) => {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_const(w, item, &c.type_, Some(&c.expr), link.anchor(&id))?;
write!(w, "</code></a></h4>\n")?;
write!(w, "</code></span></h4>\n")?;
}
clean::AssociatedTypeItem(ref bounds, ref default) => {
let id = derive_id(format!("{}.{}", item_type, name));
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id))?;
write!(w, "</code></a></h4>\n")?;
write!(w, "</code></span></h4>\n")?;
}
clean::StrippedItem(..) => return Ok(()),
_ => panic!("can't make docs for trait item with name {:?}", item.name)
Expand Down Expand Up @@ -2698,8 +2707,8 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi

write!(w, "<div class='impl-items'>")?;
for trait_item in &i.inner_impl().items {
doctraititem(w, cx, trait_item, link, render_header,
false, outer_version, trait_)?;
doc_impl_item(w, cx, trait_item, link, render_header,
false, outer_version, trait_)?;
}

fn render_default_items(w: &mut fmt::Formatter,
Expand All @@ -2716,8 +2725,8 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
let did = i.trait_.as_ref().unwrap().def_id().unwrap();
let assoc_link = AssocItemLink::GotoSource(did, &i.provided_trait_methods);

doctraititem(w, cx, trait_item, assoc_link, render_static, true,
outer_version, None)?;
doc_impl_item(w, cx, trait_item, assoc_link, render_static, true,
outer_version, None)?;
}
Ok(())
}
Expand Down
9 changes: 8 additions & 1 deletion src/librustdoc/html/static/rustdoc.css
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,20 @@ h3.impl > .out-of-band {
font-size: 21px;
}

h4 > code, h3 > code {
h4 > code, h3 > code, invisible > code {
position: inherit;
}

.in-band, code {
z-index: 5;
}

.invisible {
background: rgba(0, 0, 0, 0);
width: 100%;
display: inline-block;
}

.content .in-band {
margin: 0px;
padding: 0px;
Expand Down Expand Up @@ -660,6 +666,7 @@ span.since {

:target > code {
background: #FDFFD3;
opacity: 1;
}

/* Media Queries */
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/html/static/styles/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ h1.fqn {
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
border-bottom-color: #DDDDDD;
}
.in-band, code {
.in-band {
background-color: white;
}

Expand Down
2 changes: 2 additions & 0 deletions src/test/rustdoc/assoc-types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
// @has assoc_types/trait.Index.html
pub trait Index<I: ?Sized> {
// @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
// @has - '//*[@id="Output.t"]//code' 'type Output: ?Sized'
type Output: ?Sized;
// @has - '//*[@id="index.v"]//code' 'fn index'
// @has - '//*[@id="tymethod.index"]//code' \
// "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
fn index<'a>(&'a self, index: I) -> &'a Self::Output;
Expand Down
3 changes: 3 additions & 0 deletions src/test/rustdoc/issue-25001.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ pub trait Bar {

impl Foo<u8> {
// @has - '//*[@id="method.pass"]//code' 'fn pass()'
// @has - '//*[@id="pass.v"]//code' 'fn pass()'
pub fn pass() {}
}
impl Foo<u16> {
// @has - '//*[@id="method.pass-1"]//code' 'fn pass() -> usize'
// @has - '//*[@id="pass.v-1"]//code' 'fn pass() -> usize'
pub fn pass() -> usize { 42 }
}
impl Foo<u32> {
// @has - '//*[@id="method.pass-2"]//code' 'fn pass() -> isize'
// @has - '//*[@id="pass.v-2"]//code' 'fn pass() -> isize'
pub fn pass() -> isize { 42 }
}

Expand Down
6 changes: 6 additions & 0 deletions src/test/rustdoc/structfields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// @has structfields/Foo.t.html
// @has - struct.Foo.html
// @has structfields/struct.Foo.html
pub struct Foo {
// @has - //pre "pub a: ()"
Expand All @@ -22,13 +24,17 @@ pub struct Foo {
pub d: usize,
}

// @has structfields/Bar.t.html
// @has - struct.Bar.html
// @has structfields/struct.Bar.html
pub struct Bar {
// @has - //pre "pub a: ()"
pub a: (),
// @!has - //pre "// some fields omitted"
}

// @has structfields/Qux.t.html
// @has - enum.Qux.html
// @has structfields/enum.Qux.html
pub enum Qux {
Quz {
Expand Down

0 comments on commit 6765f7e

Please sign in to comment.