Skip to content

Commit ae644a2

Browse files
committed
add [src] links to methods on a trait's page
1 parent b491587 commit ae644a2

File tree

3 files changed

+43
-24
lines changed

3 files changed

+43
-24
lines changed

src/librustdoc/html/render/mod.rs

+12-19
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ crate type NameDoc = (String, Option<String>);
8686

8787
crate fn ensure_trailing_slash(v: &str) -> impl fmt::Display + '_ {
8888
crate::html::format::display_fn(move |f| {
89-
if !v.ends_with('/') && !v.is_empty() {
90-
write!(f, "{}/", v)
91-
} else {
92-
write!(f, "{}", v)
93-
}
89+
if !v.ends_with('/') && !v.is_empty() { write!(f, "{}/", v) } else { write!(f, "{}", v) }
9490
})
9591
}
9692

@@ -1950,11 +1946,7 @@ fn document_stability(
19501946
}
19511947

19521948
fn document_non_exhaustive_header(item: &clean::Item) -> &str {
1953-
if item.is_non_exhaustive() {
1954-
" (Non-exhaustive)"
1955-
} else {
1956-
""
1957-
}
1949+
if item.is_non_exhaustive() { " (Non-exhaustive)" } else { "" }
19581950
}
19591951

19601952
fn document_non_exhaustive(w: &mut Buffer, item: &clean::Item) {
@@ -2636,7 +2628,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
26362628
write!(w, "{}<span class=\"loading-content\">Loading content...</span>", extra_content)
26372629
}
26382630

2639-
fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item) {
2631+
fn trait_item(w: &mut Buffer, cx: &Context, m: &clean::Item, t: &clean::Item, cache: &Cache) {
26402632
let name = m.name.as_ref().unwrap();
26412633
info!("Documenting {} on {}", name, t.name.as_deref().unwrap_or_default());
26422634
let item_type = m.type_();
@@ -2645,6 +2637,7 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
26452637
render_assoc_item(w, m, AssocItemLink::Anchor(Some(&id)), ItemType::Impl);
26462638
write!(w, "</code>");
26472639
render_stability_since(w, m, t);
2640+
write_srclink(cx, m, w, cache);
26482641
write!(w, "</h3>");
26492642
document(w, cx, m, Some(t));
26502643
}
@@ -2656,8 +2649,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
26562649
"Associated Types",
26572650
"<div class=\"methods\">",
26582651
);
2659-
for t in &types {
2660-
trait_item(w, cx, *t, it);
2652+
for t in types {
2653+
trait_item(w, cx, t, it, cache);
26612654
}
26622655
write_loading_content(w, "</div>");
26632656
}
@@ -2669,8 +2662,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
26692662
"Associated Constants",
26702663
"<div class=\"methods\">",
26712664
);
2672-
for t in &consts {
2673-
trait_item(w, cx, *t, it);
2665+
for t in consts {
2666+
trait_item(w, cx, t, it, cache);
26742667
}
26752668
write_loading_content(w, "</div>");
26762669
}
@@ -2683,8 +2676,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
26832676
"Required methods",
26842677
"<div class=\"methods\">",
26852678
);
2686-
for m in &required {
2687-
trait_item(w, cx, *m, it);
2679+
for m in required {
2680+
trait_item(w, cx, m, it, cache);
26882681
}
26892682
write_loading_content(w, "</div>");
26902683
}
@@ -2695,8 +2688,8 @@ fn item_trait(w: &mut Buffer, cx: &Context, it: &clean::Item, t: &clean::Trait,
26952688
"Provided methods",
26962689
"<div class=\"methods\">",
26972690
);
2698-
for m in &provided {
2699-
trait_item(w, cx, *m, it);
2691+
for m in provided {
2692+
trait_item(w, cx, m, it, cache);
27002693
}
27012694
write_loading_content(w, "</div>");
27022695
}

src/librustdoc/html/static/rustdoc.css

+5-5
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ a {
659659
text-decoration: underline;
660660
}
661661

662-
.invisible > .srclink, h4 > code + .srclink {
662+
.invisible > .srclink, h4 > code + .srclink, h3 > code + .srclink {
663663
position: absolute;
664664
top: 0;
665665
right: 0;
@@ -857,25 +857,25 @@ body.blur > :not(#help) {
857857
top: 0;
858858
}
859859

860-
.impl-items .since, .impl .since {
860+
.impl-items .since, .impl .since, .methods .since {
861861
flex-grow: 0;
862862
padding-left: 12px;
863863
padding-right: 2px;
864864
position: initial;
865865
}
866866

867-
.impl-items .srclink, .impl .srclink {
867+
.impl-items .srclink, .impl .srclink, .methods .srclink {
868868
flex-grow: 0;
869869
/* Override header settings otherwise it's too bold */
870870
font-size: 17px;
871871
font-weight: normal;
872872
}
873873

874-
.impl-items code, .impl code {
874+
.impl-items code, .impl code, .methods code {
875875
flex-grow: 1;
876876
}
877877

878-
.impl-items h4, h4.impl, h3.impl {
878+
.impl-items h4, h4.impl, h3.impl, .methods h3 {
879879
display: flex;
880880
flex-basis: 100%;
881881
font-size: 16px;

src/test/rustdoc/trait-src-link.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#![crate_name = "quix"]
2+
pub trait Foo {
3+
// @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#4"]' '[src]'
4+
fn required();
5+
6+
// @has quix/trait.Foo.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' '[src]'
7+
fn provided() {}
8+
}
9+
10+
pub struct Bar;
11+
12+
impl Foo for Bar {
13+
// @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#14"]' '[src]'
14+
fn required() {}
15+
// @has quix/struct.Bar.html '//a[@href="../src/quix/trait-src-link.rs.html#7"]' '[src]'
16+
}
17+
18+
pub struct Baz;
19+
20+
impl Foo for Baz {
21+
// @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#22"]' '[src]'
22+
fn required() {}
23+
24+
// @has quix/struct.Baz.html '//a[@href="../src/quix/trait-src-link.rs.html#25"]' '[src]'
25+
fn provided() {}
26+
}

0 commit comments

Comments
 (0)