Skip to content

Commit 6765f7e

Browse files
committed
Review changes
1 parent 525b77e commit 6765f7e

File tree

6 files changed

+57
-30
lines changed

6 files changed

+57
-30
lines changed

src/librustdoc/html/render.rs

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,14 +2036,18 @@ fn item_trait(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
20362036
fn trait_item(w: &mut fmt::Formatter, cx: &Context, m: &clean::Item, t: &clean::Item)
20372037
-> fmt::Result {
20382038
let name = m.name.as_ref().unwrap();
2039-
let id = derive_id(format!("{}.{}", item_type(m), name));
2040-
write!(w, "<h3 id='{id}' class='method stab {stab}'><code>",
2039+
let item_type = item_type(m);
2040+
let id = derive_id(format!("{}.{}", item_type, name));
2041+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
2042+
write!(w, "<h3 id='{id}' class='method stab {stab}'>\
2043+
<span id='{ns_id}' class='invisible'><code>",
20412044
id = id,
2042-
stab = m.stability_class())?;
2045+
stab = m.stability_class(),
2046+
ns_id = ns_id)?;
20432047
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)))?;
20442048
write!(w, "</code>")?;
20452049
render_stability_since(w, m, t)?;
2046-
write!(w, "</h3>")?;
2050+
write!(w, "</span></h3>")?;
20472051
document(w, cx, m)?;
20482052
Ok(())
20492053
}
@@ -2283,9 +2287,9 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22832287
write!(w, "<h2 class='fields'>Fields</h2>")?;
22842288
for (field, ty) in fields {
22852289
write!(w, "<span id='{item_type}.{name}' class='{item_type}'>
2286-
<a id='{name}.{name_space}'>
2290+
<span id='{name}.{name_space}' class='invisible'>
22872291
<code>{name}: {ty}</code>
2288-
</a></span><span class='stab {stab}'></span>",
2292+
</span></span><span class='stab {stab}'></span>",
22892293
item_type = ItemType::StructField,
22902294
name_space = ItemType::StructField.name_space(),
22912295
stab = field.stability_class(),
@@ -2357,7 +2361,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23572361
write!(w, "<h2 class='variants'>Variants</h2>\n")?;
23582362
for variant in &e.variants {
23592363
write!(w, "<span id='{item_type}.{name}' class='variant'>\
2360-
<a id='{name}.{name_space}'><code>{name}",
2364+
<span id='{name}.{name_space}' class='invisible'><code>{name}",
23612365
item_type = ItemType::Variant,
23622366
name_space = ItemType::Variant.name_space(),
23632367
name = variant.name.as_ref().unwrap())?;
@@ -2373,7 +2377,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23732377
write!(w, ")")?;
23742378
}
23752379
}
2376-
write!(w, "</code></a></span>")?;
2380+
write!(w, "</code></span></span>")?;
23772381
document(w, cx, variant)?;
23782382

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

2609-
fn doctraititem(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
2610-
link: AssocItemLink, render_static: bool,
2611-
is_default_item: bool, outer_version: Option<&str>,
2612-
trait_: Option<&clean::Trait>) -> fmt::Result {
2613+
fn doc_impl_item(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
2614+
link: AssocItemLink, render_static: bool,
2615+
is_default_item: bool, outer_version: Option<&str>,
2616+
trait_: Option<&clean::Trait>) -> fmt::Result {
26132617
let item_type = item_type(item);
26142618
let name = item.name.as_ref().unwrap();
26152619

@@ -2624,42 +2628,47 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26242628
// Only render when the method is not static or we allow static methods
26252629
if !is_static || render_static {
26262630
let id = derive_id(format!("{}.{}", item_type, name));
2631+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26272632
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2628-
write!(w, "<a id='{}.{}'>", name, item_type.name_space())?;
2633+
write!(w, "<span id='{}' class='invisible'>", ns_id)?;
26292634
write!(w, "<code>")?;
26302635
render_assoc_item(w, item, link.anchor(&id))?;
26312636
write!(w, "</code>")?;
26322637
render_stability_since_raw(w, item.stable_since(), outer_version)?;
2633-
write!(w, "</a></h4>\n")?;
2638+
write!(w, "</span></h4>\n")?;
26342639
}
26352640
}
26362641
clean::TypedefItem(ref tydef, _) => {
26372642
let id = derive_id(format!("{}.{}", ItemType::AssociatedType, name));
2643+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26382644
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2639-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2645+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26402646
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id))?;
2641-
write!(w, "</code></a></h4>\n")?;
2647+
write!(w, "</code></span></h4>\n")?;
26422648
}
26432649
clean::AssociatedConstItem(ref ty, ref default) => {
26442650
let id = derive_id(format!("{}.{}", item_type, name));
2651+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26452652
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2646-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2653+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26472654
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
2648-
write!(w, "</code></a></h4>\n")?;
2655+
write!(w, "</code></span></h4>\n")?;
26492656
}
26502657
clean::ConstantItem(ref c) => {
26512658
let id = derive_id(format!("{}.{}", item_type, name));
2659+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26522660
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2653-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2661+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26542662
assoc_const(w, item, &c.type_, Some(&c.expr), link.anchor(&id))?;
2655-
write!(w, "</code></a></h4>\n")?;
2663+
write!(w, "</code></span></h4>\n")?;
26562664
}
26572665
clean::AssociatedTypeItem(ref bounds, ref default) => {
26582666
let id = derive_id(format!("{}.{}", item_type, name));
2667+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26592668
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2660-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2669+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26612670
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id))?;
2662-
write!(w, "</code></a></h4>\n")?;
2671+
write!(w, "</code></span></h4>\n")?;
26632672
}
26642673
clean::StrippedItem(..) => return Ok(()),
26652674
_ => panic!("can't make docs for trait item with name {:?}", item.name)
@@ -2698,8 +2707,8 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26982707

26992708
write!(w, "<div class='impl-items'>")?;
27002709
for trait_item in &i.inner_impl().items {
2701-
doctraititem(w, cx, trait_item, link, render_header,
2702-
false, outer_version, trait_)?;
2710+
doc_impl_item(w, cx, trait_item, link, render_header,
2711+
false, outer_version, trait_)?;
27032712
}
27042713

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

2719-
doctraititem(w, cx, trait_item, assoc_link, render_static, true,
2720-
outer_version, None)?;
2728+
doc_impl_item(w, cx, trait_item, assoc_link, render_static, true,
2729+
outer_version, None)?;
27212730
}
27222731
Ok(())
27232732
}

src/librustdoc/html/static/rustdoc.css

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,14 +284,20 @@ h3.impl > .out-of-band {
284284
font-size: 21px;
285285
}
286286

287-
h4 > code, h3 > code {
287+
h4 > code, h3 > code, invisible > code {
288288
position: inherit;
289289
}
290290

291291
.in-band, code {
292292
z-index: 5;
293293
}
294294

295+
.invisible {
296+
background: rgba(0, 0, 0, 0);
297+
width: 100%;
298+
display: inline-block;
299+
}
300+
295301
.content .in-band {
296302
margin: 0px;
297303
padding: 0px;
@@ -660,6 +666,7 @@ span.since {
660666

661667
:target > code {
662668
background: #FDFFD3;
669+
opacity: 1;
663670
}
664671

665672
/* Media Queries */

src/librustdoc/html/static/styles/main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ h1.fqn {
2626
h2, h3:not(.impl):not(.method):not(.type):not(.tymethod), h4:not(.method):not(.type):not(.tymethod) {
2727
border-bottom-color: #DDDDDD;
2828
}
29-
.in-band, code {
29+
.in-band {
3030
background-color: white;
3131
}
3232

src/test/rustdoc/assoc-types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
// @has assoc_types/trait.Index.html
1414
pub trait Index<I: ?Sized> {
1515
// @has - '//*[@id="associatedtype.Output"]//code' 'type Output: ?Sized'
16+
// @has - '//*[@id="Output.t"]//code' 'type Output: ?Sized'
1617
type Output: ?Sized;
18+
// @has - '//*[@id="index.v"]//code' 'fn index'
1719
// @has - '//*[@id="tymethod.index"]//code' \
1820
// "fn index<'a>(&'a self, index: I) -> &'a Self::Output"
1921
fn index<'a>(&'a self, index: I) -> &'a Self::Output;

src/test/rustdoc/issue-25001.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,17 @@ pub trait Bar {
1919

2020
impl Foo<u8> {
2121
// @has - '//*[@id="method.pass"]//code' 'fn pass()'
22+
// @has - '//*[@id="pass.v"]//code' 'fn pass()'
2223
pub fn pass() {}
2324
}
2425
impl Foo<u16> {
2526
// @has - '//*[@id="method.pass-1"]//code' 'fn pass() -> usize'
27+
// @has - '//*[@id="pass.v-1"]//code' 'fn pass() -> usize'
2628
pub fn pass() -> usize { 42 }
2729
}
2830
impl Foo<u32> {
2931
// @has - '//*[@id="method.pass-2"]//code' 'fn pass() -> isize'
32+
// @has - '//*[@id="pass.v-2"]//code' 'fn pass() -> isize'
3033
pub fn pass() -> isize { 42 }
3134
}
3235

src/test/rustdoc/structfields.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
// @has structfields/Foo.t.html
12+
// @has - struct.Foo.html
1113
// @has structfields/struct.Foo.html
1214
pub struct Foo {
1315
// @has - //pre "pub a: ()"
@@ -22,13 +24,17 @@ pub struct Foo {
2224
pub d: usize,
2325
}
2426

27+
// @has structfields/Bar.t.html
28+
// @has - struct.Bar.html
2529
// @has structfields/struct.Bar.html
2630
pub struct Bar {
2731
// @has - //pre "pub a: ()"
2832
pub a: (),
2933
// @!has - //pre "// some fields omitted"
3034
}
3135

36+
// @has structfields/Qux.t.html
37+
// @has - enum.Qux.html
3238
// @has structfields/enum.Qux.html
3339
pub enum Qux {
3440
Quz {

0 commit comments

Comments
 (0)