Skip to content

Commit 862b911

Browse files
authored
Rollup merge of #129560 - GuillaumeGomez:impl-assoc-type-source-link, r=notriddle
[rustdoc] Generate source link on impl associated types Currently, impl associated types are generated but don't get a source link. This PR fixes that. Before: ![image](https://github.com/user-attachments/assets/3a22adb5-8b66-4124-9267-7c26eed1aa5e) After: ![Screenshot from 2024-08-25 16-31-36](https://github.com/user-attachments/assets/6e9b35e7-4357-4ecf-8c49-1d8294051283) r? `@notriddle`
2 parents 53f5294 + ca6be74 commit 862b911

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/librustdoc/html/render/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1730,6 +1730,7 @@ fn render_impl(
17301730
let source_id = format!("{item_type}.{name}");
17311731
let id = cx.derive_id(&source_id);
17321732
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
1733+
render_rightside(w, cx, item, render_mode);
17331734
if trait_.is_some() {
17341735
// Anchors are only used on trait impls.
17351736
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
@@ -1751,6 +1752,7 @@ fn render_impl(
17511752
let source_id = format!("{item_type}.{name}");
17521753
let id = cx.derive_id(&source_id);
17531754
write!(w, "<section id=\"{id}\" class=\"{item_type}{in_trait_class}\">");
1755+
render_rightside(w, cx, item, render_mode);
17541756
if trait_.is_some() {
17551757
// Anchors are only used on trait impls.
17561758
write!(w, "<a href=\"#{id}\" class=\"anchor\">§</a>");
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<section id="associatedtype.Y" class="associatedtype"><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
1+
<section id="associatedtype.Y" class="associatedtype"><a class="src rightside" href="../src/foo/anchors.rs.html#45">source</a><h4 class="code-header">pub type <a href="#associatedtype.Y" class="associatedtype">Y</a> = <a class="primitive" href="{{channel}}/std/primitive.u32.html">u32</a></h4></section>
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// This test ensures that the source links are generated for impl associated types.
2+
3+
#![crate_name = "foo"]
4+
#![feature(inherent_associated_types)]
5+
#![allow(incomplete_features)]
6+
7+
//@ has 'foo/struct.Bar.html'
8+
pub struct Bar;
9+
10+
impl Bar {
11+
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a' 'source'
12+
//@ has - '//*[@id="implementations-list"]//*[@id="associatedtype.Y"]/a/@href' \
13+
// '../src/foo/assoc-type-source-link.rs.html#14'
14+
pub type Y = u8;
15+
}
16+
17+
pub trait Foo {
18+
type Z;
19+
}
20+
21+
impl Foo for Bar {
22+
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a' 'source'
23+
//@ has - '//*[@id="trait-implementations-list"]//*[@id="associatedtype.Z"]/a/@href' \
24+
// '../src/foo/assoc-type-source-link.rs.html#25'
25+
type Z = u8;
26+
}

0 commit comments

Comments
 (0)