Skip to content

Commit 879637f

Browse files
committed
Review changes
1 parent 77ca7dd commit 879637f

File tree

9 files changed

+92
-39
lines changed

9 files changed

+92
-39
lines changed

src/librustdoc/html/render.rs

+66-37
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
}
@@ -2282,12 +2286,19 @@ fn item_struct(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
22822286
if fields.peek().is_some() {
22832287
write!(w, "<h2 class='fields'>Fields</h2>")?;
22842288
for (field, ty) in fields {
2285-
write!(w, "<span id='{item_type}.{name}' class='{item_type}'>
2286-
<a id='{name}.{name_space}'>
2289+
let id = derive_id(format!("{}.{}",
2290+
ItemType::StructField,
2291+
field.name.as_ref().unwrap()));
2292+
let ns_id = derive_id(format!("{}.{}",
2293+
field.name.as_ref().unwrap(),
2294+
ItemType::StructField.name_space()));
2295+
write!(w, "<span id='{id}' class='{item_type}'>
2296+
<span id='{ns_id}' class='invisible'>
22872297
<code>{name}: {ty}</code>
2288-
</a></span><span class='stab {stab}'></span>",
2298+
</span></span><span class='stab {stab}'></span>",
22892299
item_type = ItemType::StructField,
2290-
name_space = ItemType::StructField.name_space(),
2300+
id = id,
2301+
ns_id = ns_id,
22912302
stab = field.stability_class(),
22922303
name = field.name.as_ref().unwrap(),
22932304
ty = ty)?;
@@ -2356,10 +2367,16 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23562367
if !e.variants.is_empty() {
23572368
write!(w, "<h2 class='variants'>Variants</h2>\n")?;
23582369
for variant in &e.variants {
2359-
write!(w, "<span id='{item_type}.{name}' class='variant'>\
2360-
<a id='{name}.{name_space}'><code>{name}",
2361-
item_type = ItemType::Variant,
2362-
name_space = ItemType::Variant.name_space(),
2370+
let id = derive_id(format!("{}.{}",
2371+
ItemType::Variant,
2372+
variant.name.as_ref().unwrap()));
2373+
let ns_id = derive_id(format!("{}.{}",
2374+
variant.name.as_ref().unwrap(),
2375+
ItemType::Variant.name_space()));
2376+
write!(w, "<span id='{id}' class='variant'>\
2377+
<span id='{ns_id}' class='invisible'><code>{name}",
2378+
id = id,
2379+
ns_id = ns_id,
23632380
name = variant.name.as_ref().unwrap())?;
23642381
if let clean::VariantItem(ref var) = variant.inner {
23652382
if let clean::TupleVariant(ref tys) = var.kind {
@@ -2373,7 +2390,7 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23732390
write!(w, ")")?;
23742391
}
23752392
}
2376-
write!(w, "</code></a></span>")?;
2393+
write!(w, "</code></span></span>")?;
23772394
document(w, cx, variant)?;
23782395

23792396
use clean::{Variant, StructVariant};
@@ -2383,14 +2400,21 @@ fn item_enum(w: &mut fmt::Formatter, cx: &Context, it: &clean::Item,
23832400
for field in &s.fields {
23842401
use clean::StructFieldItem;
23852402
if let StructFieldItem(ref ty) = field.inner {
2403+
let id = derive_id(format!("variant.{}.field.{}",
2404+
variant.name.as_ref().unwrap(),
2405+
field.name.as_ref().unwrap()));
2406+
let ns_id = derive_id(format!("{}.{}.{}.{}",
2407+
variant.name.as_ref().unwrap(),
2408+
ItemType::Variant.name_space(),
2409+
field.name.as_ref().unwrap(),
2410+
ItemType::StructField.name_space()));
23862411
write!(w, "<tr><td \
2387-
id='variant.{v}.field.{f}'>\
2388-
<a id='{v}.{vns}.{f}.{fns}'>\
2389-
<code>{f}:&nbsp;{t}</code></a></td><td>",
2390-
v = variant.name.as_ref().unwrap(),
2412+
id='{id}'>\
2413+
<span id='{ns_id}' class='invisible'>\
2414+
<code>{f}:&nbsp;{t}</code></span></td><td>",
2415+
id = id,
2416+
ns_id = ns_id,
23912417
f = field.name.as_ref().unwrap(),
2392-
vns = ItemType::Variant.name_space(),
2393-
fns = ItemType::StructField.name_space(),
23942418
t = *ty)?;
23952419
document(w, cx, field)?;
23962420
write!(w, "</td></tr>")?;
@@ -2606,10 +2630,10 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26062630
}
26072631
}
26082632

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 {
2633+
fn doc_impl_item(w: &mut fmt::Formatter, cx: &Context, item: &clean::Item,
2634+
link: AssocItemLink, render_static: bool,
2635+
is_default_item: bool, outer_version: Option<&str>,
2636+
trait_: Option<&clean::Trait>) -> fmt::Result {
26132637
let item_type = item_type(item);
26142638
let name = item.name.as_ref().unwrap();
26152639

@@ -2624,42 +2648,47 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26242648
// Only render when the method is not static or we allow static methods
26252649
if !is_static || render_static {
26262650
let id = derive_id(format!("{}.{}", item_type, name));
2651+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26272652
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2628-
write!(w, "<a id='{}.{}'>", name, item_type.name_space())?;
2653+
write!(w, "<span id='{}' class='invisible'>", ns_id)?;
26292654
write!(w, "<code>")?;
26302655
render_assoc_item(w, item, link.anchor(&id))?;
26312656
write!(w, "</code>")?;
26322657
render_stability_since_raw(w, item.stable_since(), outer_version)?;
2633-
write!(w, "</a></h4>\n")?;
2658+
write!(w, "</span></h4>\n")?;
26342659
}
26352660
}
26362661
clean::TypedefItem(ref tydef, _) => {
26372662
let id = derive_id(format!("{}.{}", ItemType::AssociatedType, name));
2663+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26382664
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2639-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2665+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26402666
assoc_type(w, item, &Vec::new(), Some(&tydef.type_), link.anchor(&id))?;
2641-
write!(w, "</code></a></h4>\n")?;
2667+
write!(w, "</code></span></h4>\n")?;
26422668
}
26432669
clean::AssociatedConstItem(ref ty, ref default) => {
26442670
let id = derive_id(format!("{}.{}", item_type, name));
2671+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26452672
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2646-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2673+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26472674
assoc_const(w, item, ty, default.as_ref(), link.anchor(&id))?;
2648-
write!(w, "</code></a></h4>\n")?;
2675+
write!(w, "</code></span></h4>\n")?;
26492676
}
26502677
clean::ConstantItem(ref c) => {
26512678
let id = derive_id(format!("{}.{}", item_type, name));
2679+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26522680
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2653-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2681+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26542682
assoc_const(w, item, &c.type_, Some(&c.expr), link.anchor(&id))?;
2655-
write!(w, "</code></a></h4>\n")?;
2683+
write!(w, "</code></span></h4>\n")?;
26562684
}
26572685
clean::AssociatedTypeItem(ref bounds, ref default) => {
26582686
let id = derive_id(format!("{}.{}", item_type, name));
2687+
let ns_id = derive_id(format!("{}.{}", name, item_type.name_space()));
26592688
write!(w, "<h4 id='{}' class='{}'>", id, item_type)?;
2660-
write!(w, "<a id='{}.{}'><code>", name, item_type.name_space())?;
2689+
write!(w, "<span id='{}' class='invisible'><code>", ns_id)?;
26612690
assoc_type(w, item, bounds, default.as_ref(), link.anchor(&id))?;
2662-
write!(w, "</code></a></h4>\n")?;
2691+
write!(w, "</code></span></h4>\n")?;
26632692
}
26642693
clean::StrippedItem(..) => return Ok(()),
26652694
_ => panic!("can't make docs for trait item with name {:?}", item.name)
@@ -2698,8 +2727,8 @@ fn render_impl(w: &mut fmt::Formatter, cx: &Context, i: &Impl, link: AssocItemLi
26982727

26992728
write!(w, "<div class='impl-items'>")?;
27002729
for trait_item in &i.inner_impl().items {
2701-
doctraititem(w, cx, trait_item, link, render_header,
2702-
false, outer_version, trait_)?;
2730+
doc_impl_item(w, cx, trait_item, link, render_header,
2731+
false, outer_version, trait_)?;
27032732
}
27042733

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

2719-
doctraititem(w, cx, trait_item, assoc_link, render_static, true,
2720-
outer_version, None)?;
2748+
doc_impl_item(w, cx, trait_item, assoc_link, render_static, true,
2749+
outer_version, None)?;
27212750
}
27222751
Ok(())
27232752
}

src/librustdoc/html/static/rustdoc.css

+8-1
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

+1-1
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

+2
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-19190.rs

+3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ impl Deref for Bar {
2323
fn deref(&self) -> &Foo { loop {} }
2424
}
2525

26+
// @has issue_19190/Bar.t.html
2627
// @has issue_19190/struct.Bar.html
28+
// @has - '//*[@id="foo.v"]' 'fn foo(&self)'
2729
// @has - '//*[@id="method.foo"]' 'fn foo(&self)'
30+
// @!has - '//*[@id="static_foo.v"]' 'fn static_foo()'
2831
// @!has - '//*[@id="method.static_foo"]' 'fn static_foo()'

src/test/rustdoc/issue-21092.rs

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
extern crate issue_21092;
1515

16+
// @has issue_21092/Bar.t.html
1617
// @has issue_21092/struct.Bar.html
1718
// @has - '//*[@id="associatedtype.Bar"]' 'type Bar = i32'
1819
pub use issue_21092::{Foo, Bar};

src/test/rustdoc/issue-25001.rs

+3
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/src-links.rs

+2
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,13 @@ pub mod bar {
2424
// @has foo/bar/baz/index.html '//a/@href' '../../../src/foo/src-links.rs.html'
2525
pub mod baz {
2626
/// Dox
27+
// @has foo/bar/baz/baz.v.html
2728
// @has foo/bar/baz/fn.baz.html '//a/@href' '../../../src/foo/src-links.rs.html'
2829
pub fn baz() { }
2930
}
3031

3132
/// Dox
33+
// @has foo/bar/Foobar.t.html
3234
// @has foo/bar/trait.Foobar.html '//a/@href' '../../src/foo/src-links.rs.html'
3335
pub trait Foobar { fn dummy(&self) { } }
3436

src/test/rustdoc/structfields.rs

+6
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)