Skip to content

Commit a21affa

Browse files
Fix invalid link generation for type alias methods
1 parent 69408a8 commit a21affa

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

src/librustdoc/html/render/write_shared.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,18 +568,14 @@ impl TypeAliasPart {
568568
if let Some(ret) = &mut ret {
569569
ret.aliases.push(type_alias_fqp);
570570
} else {
571-
let target_did = impl_
572-
.inner_impl()
573-
.trait_
574-
.as_ref()
575-
.map(|trait_| trait_.def_id())
576-
.or_else(|| impl_.inner_impl().for_.def_id(&cx.shared.cache));
571+
let target_trait_did =
572+
impl_.inner_impl().trait_.as_ref().map(|trait_| trait_.def_id());
577573
let provided_methods;
578-
let assoc_link = if let Some(target_did) = target_did {
574+
let assoc_link = if let Some(target_trait_did) = target_trait_did {
579575
provided_methods =
580576
impl_.inner_impl().provided_trait_methods(cx.tcx());
581577
AssocItemLink::GotoSource(
582-
ItemId::DefId(target_did),
578+
ItemId::DefId(target_trait_did),
583579
&provided_methods,
584580
)
585581
} else {

tests/rustdoc-gui/src/test_docs/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -786,3 +786,13 @@ pub mod tooltips {
786786
Vec::new()
787787
}
788788
}
789+
790+
pub mod tyalias {
791+
pub struct X<T>(pub T);
792+
793+
impl<T: std::fmt::Debug> X<T> {
794+
pub fn blob(&self) {}
795+
}
796+
797+
pub type Y = X<u8>;
798+
}

tests/rustdoc-gui/type-alias.goml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// This test ensures that we correctly generate links to methods on type aliases.
2+
go-to: "file://" + |DOC_PATH| + "/test_docs/tyalias/type.Y.html"
3+
4+
// It's generated with JS so we need to wait for it to be done generating.
5+
wait-for: "#implementations"
6+
// We check that it's "#method." and not "#tymethod.".
7+
assert-text: ('#method\.blob a.fn[href="#method.blob"]', "blob")

0 commit comments

Comments
 (0)