diff --git a/src/librustdoc/html/render/write_shared.rs b/src/librustdoc/html/render/write_shared.rs
index 6045b9a77eca..31da7b7de920 100644
--- a/src/librustdoc/html/render/write_shared.rs
+++ b/src/librustdoc/html/render/write_shared.rs
@@ -568,18 +568,14 @@ impl TypeAliasPart {
if let Some(ret) = &mut ret {
ret.aliases.push(type_alias_fqp);
} else {
- let target_did = impl_
- .inner_impl()
- .trait_
- .as_ref()
- .map(|trait_| trait_.def_id())
- .or_else(|| impl_.inner_impl().for_.def_id(&cx.shared.cache));
+ let target_trait_did =
+ impl_.inner_impl().trait_.as_ref().map(|trait_| trait_.def_id());
let provided_methods;
- let assoc_link = if let Some(target_did) = target_did {
+ let assoc_link = if let Some(target_trait_did) = target_trait_did {
provided_methods =
impl_.inner_impl().provided_trait_methods(cx.tcx());
AssocItemLink::GotoSource(
- ItemId::DefId(target_did),
+ ItemId::DefId(target_trait_did),
&provided_methods,
)
} else {
diff --git a/tests/rustdoc-gui/src/test_docs/lib.rs b/tests/rustdoc-gui/src/test_docs/lib.rs
index c0771583ab65..0ee2a66d4b68 100644
--- a/tests/rustdoc-gui/src/test_docs/lib.rs
+++ b/tests/rustdoc-gui/src/test_docs/lib.rs
@@ -786,3 +786,13 @@ pub mod tooltips {
Vec::new()
}
}
+
+pub mod tyalias {
+ pub struct X(pub T);
+
+ impl X {
+ pub fn blob(&self) {}
+ }
+
+ pub type Y = X;
+}
diff --git a/tests/rustdoc-gui/type-alias.goml b/tests/rustdoc-gui/type-alias.goml
new file mode 100644
index 000000000000..a07f1b4eb814
--- /dev/null
+++ b/tests/rustdoc-gui/type-alias.goml
@@ -0,0 +1,7 @@
+// This test ensures that we correctly generate links to methods on type aliases.
+go-to: "file://" + |DOC_PATH| + "/test_docs/tyalias/type.Y.html"
+
+// It's generated with JS so we need to wait for it to be done generating.
+wait-for: "#implementations"
+// We check that it's "#method." and not "#tymethod.".
+assert-text: ('#method\.blob a.fn[href="#method.blob"]', "blob")