Skip to content

Commit 2968a5a

Browse files
Fix DOM errors
1 parent b56cec0 commit 2968a5a

File tree

3 files changed

+28
-32
lines changed

3 files changed

+28
-32
lines changed

src/librustdoc/html/render.rs

+25-29
Original file line numberDiff line numberDiff line change
@@ -3037,15 +3037,14 @@ fn item_trait(
30373037
let item_type = m.type_();
30383038
let id = cx.derive_id(format!("{}.{}", item_type, name));
30393039
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
3040-
write!(w, "{extra}<h3 id='{id}' class='method'>\
3041-
<span id='{ns_id}' class='invisible'><code>",
3040+
write!(w, "{extra}<h3 id='{id}' class='method'><code id='{ns_id}'>",
30423041
extra = render_spotlight_traits(m)?,
30433042
id = id,
30443043
ns_id = ns_id)?;
30453044
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl)?;
30463045
write!(w, "</code>")?;
30473046
render_stability_since(w, m, t)?;
3048-
write!(w, "</span></h3>")?;
3047+
write!(w, "</h3>")?;
30493048
document(w, cx, m)?;
30503049
Ok(())
30513050
}
@@ -3374,11 +3373,10 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
33743373
let ns_id = cx.derive_id(format!("{}.{}",
33753374
field.name.as_ref().unwrap(),
33763375
ItemType::StructField.name_space()));
3377-
write!(w, "<span id=\"{id}\" class=\"{item_type} small-section-header\">
3378-
<a href=\"#{id}\" class=\"anchor field\"></a>
3379-
<span id=\"{ns_id}\" class='invisible'>
3380-
<code>{name}: {ty}</code>
3381-
</span></span>",
3376+
write!(w, "<span id=\"{id}\" class=\"{item_type} small-section-header\">\
3377+
<a href=\"#{id}\" class=\"anchor field\"></a>\
3378+
<code id=\"{ns_id}\">{name}: {ty}</code>\
3379+
</span>",
33823380
item_type = ItemType::StructField,
33833381
id = id,
33843382
ns_id = ns_id,
@@ -3510,7 +3508,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
35103508
ItemType::Variant.name_space()));
35113509
write!(w, "<span id=\"{id}\" class=\"variant small-section-header\">\
35123510
<a href=\"#{id}\" class=\"anchor field\"></a>\
3513-
<span id='{ns_id}' class='invisible'><code>{name}",
3511+
<code id='{ns_id}'>{name}",
35143512
id = id,
35153513
ns_id = ns_id,
35163514
name = variant.name.as_ref().unwrap())?;
@@ -3526,7 +3524,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
35263524
write!(w, ")")?;
35273525
}
35283526
}
3529-
write!(w, "</code></span></span>")?;
3527+
write!(w, "</code></span>")?;
35303528
document(w, cx, variant)?;
35313529

35323530
use clean::{Variant, VariantKind};
@@ -3553,8 +3551,8 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
35533551
ItemType::StructField.name_space()));
35543552
write!(w, "<span id=\"{id}\" class=\"variant small-section-header\">\
35553553
<a href=\"#{id}\" class=\"anchor field\"></a>\
3556-
<span id='{ns_id}' class='invisible'><code>{f}:&nbsp;{t}\
3557-
</code></span></span>",
3554+
<code id='{ns_id}'>{f}:&nbsp;{t}\
3555+
</code></span>",
35583556
id = id,
35593557
ns_id = ns_id,
35603558
f = field.name.as_ref().unwrap(),
@@ -3999,7 +3997,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
39993997
id, i.inner_impl())?;
40003998
}
40013999
write!(w, "<a href='#{}' class='anchor'></a>", id)?;
4002-
write!(w, "</span></td><td><span class='out-of-band'>")?;
4000+
write!(w, "</td><td><span class='out-of-band'>")?;
40034001
let since = i.impl_item.stability.as_ref().map(|s| &s.since[..]);
40044002
if let Some(l) = (Item { item: &i.impl_item, cx: cx }).src_href() {
40054003
write!(w, "<div class='ghost'></div>")?;
@@ -4009,7 +4007,7 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40094007
} else {
40104008
render_stability_since_raw(w, since, outer_version)?;
40114009
}
4012-
write!(w, "</span></td></tr></tbody></table></h3>")?;
4010+
write!(w, "</span></td></tr></tbody></table></span></h3>")?;
40134011
if let Some(ref dox) = cx.shared.maybe_collapsed_doc_value(&i.impl_item) {
40144012
let mut ids = cx.id_map.borrow_mut();
40154013
write!(w, "<div class='docblock'>{}</div>",
@@ -4045,30 +4043,29 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40454043
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
40464044
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
40474045
write!(w, "{}", spotlight_decl(decl)?)?;
4048-
write!(w, "<span id='{}' class='invisible'>", ns_id)?;
4049-
write!(w, "<table class='table-display'><tbody><tr><td><code>")?;
4046+
write!(w, "<table id='{}' class='table-display'><tbody><tr><td><code>", ns_id)?;
40504047
render_assoc_item(w, item, link.anchor(&id), ItemType::Impl)?;
40514048
write!(w, "</code>")?;
40524049
if let Some(l) = (Item { cx, item }).src_href() {
4053-
write!(w, "</span></td><td><span class='out-of-band'>")?;
4050+
write!(w, "</td><td><span class='out-of-band'>")?;
40544051
write!(w, "<div class='ghost'></div>")?;
40554052
render_stability_since_raw(w, item.stable_since(), outer_version)?;
4056-
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a>",
4053+
write!(w, "<a class='srclink' href='{}' title='{}'>[src]</a></span>",
40574054
l, "goto source code")?;
40584055
} else {
40594056
write!(w, "</td><td>")?;
40604057
render_stability_since_raw(w, item.stable_since(), outer_version)?;
40614058
}
4062-
write!(w, "</td></tr></tbody></table></span></h4>")?;
4059+
write!(w, "</td></tr></tbody></table></h4>")?;
40634060
}
40644061
}
40654062
clean::TypedefItem(ref tydef, _) => {
40664063
let id = cx.derive_id(format!("{}.{}", ItemType::AssociatedType, name));
40674064
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
40684065
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
4069-
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
4066+
write!(w, "<code id='{}'>", ns_id)?;
40704067
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id))?;
4071-
write!(w, "</code></span></h4>")?;
4068+
write!(w, "</code></h4>")?;
40724069
}
40734070
clean::AssociatedConstItem(ref ty, ref default) => {
40744071
let mut version = String::new();
@@ -4078,19 +4075,18 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
40784075
let id = cx.derive_id(format!("{}.{}", item_type, name));
40794076
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
40804077
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
4081-
write!(w, "<span id='{}' class='invisible'>", ns_id)?;
40824078
if !version.is_empty() {
4083-
write!(w, "<table class='table-display'><tbody><tr><td><code>")?;
4079+
write!(w, "<table id='{}' class='table-display'><tbody><tr><td><code>", ns_id)?;
40844080
} else {
4085-
write!(w, "<code>")?;
4081+
write!(w, "<code id='{}'>", ns_id)?;
40864082
}
40874083
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
40884084
if !version.is_empty() {
40894085
write!(w, "</code>")?;
40904086
}
40914087
let src = if let Some(l) = (Item { cx, item }).src_href() {
40924088
if !version.is_empty() {
4093-
write!(w, "</span></td><td><span class='out-of-band'>")?;
4089+
write!(w, "</td><td><span class='out-of-band'>")?;
40944090
write!(w, "<div class='ghost'></div>{}", version)?;
40954091
}
40964092
format!("<a class='srclink' href='{}' title='{}'>[src]</a>",
@@ -4102,18 +4098,18 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
41024098
String::new()
41034099
};
41044100
if version.is_empty() {
4105-
write!(w, "</code>{}</span></h4>", src)?;
4101+
write!(w, "</code>{}</h4>", src)?;
41064102
} else {
4107-
write!(w, "{}</td></tr></tbody></table></span></h4>", src)?;
4103+
write!(w, "{}</span></td></tr></tbody></table></h4>", src)?;
41084104
}
41094105
}
41104106
clean::AssociatedTypeItem(ref bounds, ref default) => {
41114107
let id = cx.derive_id(format!("{}.{}", item_type, name));
41124108
let ns_id = cx.derive_id(format!("{}.{}", name, item_type.name_space()));
41134109
write!(w, "<h4 id='{}' class=\"{}{}\">", id, item_type, extra_class)?;
4114-
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
4110+
write!(w, "<code id='{}'>", ns_id)?;
41154111
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id))?;
4116-
write!(w, "</code></span></h4>\n")?;
4112+
write!(w, "</code></h4>")?;
41174113
}
41184114
clean::StrippedItem(..) => return Ok(()),
41194115
_ => panic!("can't make docs for trait item with name {:?}", item.name)

src/librustdoc/html/static/rustdoc.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ a {
611611
text-decoration: underline;
612612
}
613613

614-
.invisible > .srclink {
614+
.invisible > .srclink, h4 > code + .srclink {
615615
position: absolute;
616616
top: 0;
617617
right: 0;

src/test/rustdoc/assoc-types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
// @has assoc_types/trait.Index.html
1616
pub trait Index<I: ?Sized> {
1717
// @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
18-
// @has - '//*[@id="Output.t"]//code' 'type Output: ?Sized'
18+
// @has - '//code[@id="Output.t"]' 'type Output: ?Sized'
1919
type Output: ?Sized;
20-
// @has - '//*[@id="index.v"]//code' 'fn index'
20+
// @has - '//code[@id="index.v"]' 'fn index'
2121
// @has - '//*[@id="tymethod.index"]//code' \
2222
// "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
2323
// @has - '//*[@id="tymethod.index"]//code//a[@href="../assoc_types/trait.Index.html#associatedtype.Output"]' \

0 commit comments

Comments
 (0)