From 6509c42d165eab4a6a91fd94114e3df85532fd80 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 10 May 2023 22:49:05 +0000 Subject: [PATCH] Use proper impl self type for alias impl in rustdoc --- src/librustdoc/clean/mod.rs | 17 +++++++++-------- tests/rustdoc/impl-alias-substituted.rs | 9 +++++++++ 2 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 tests/rustdoc/impl-alias-substituted.rs diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index c432ce3c324..59a3e631724 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -2414,14 +2414,15 @@ fn clean_impl<'tcx>( } let for_ = clean_ty(impl_.self_ty, cx); - let type_alias = for_.def_id(&cx.cache).and_then(|did| match tcx.def_kind(did) { - DefKind::TyAlias => Some(clean_middle_ty( - ty::Binder::dummy(tcx.type_of(did).subst_identity()), - cx, - Some(did), - )), - _ => None, - }); + let type_alias = + for_.def_id(&cx.cache).and_then(|alias_def_id: DefId| match tcx.def_kind(alias_def_id) { + DefKind::TyAlias => Some(clean_middle_ty( + ty::Binder::dummy(tcx.type_of(def_id).subst_identity()), + cx, + Some(def_id.to_def_id()), + )), + _ => None, + }); let mut make_item = |trait_: Option, for_: Type, items: Vec| { let kind = ImplItem(Box::new(Impl { unsafety: impl_.unsafety, diff --git a/tests/rustdoc/impl-alias-substituted.rs b/tests/rustdoc/impl-alias-substituted.rs new file mode 100644 index 00000000000..82dfffe5f1c --- /dev/null +++ b/tests/rustdoc/impl-alias-substituted.rs @@ -0,0 +1,9 @@ +pub struct Matrix([[T; N]; M]); + +pub type Vector = Matrix; + +// @has "impl_alias_substituted/struct.Matrix.html" '//*[@class="impl"]//h3[@class="code-header"]' \ +// "impl Matrix" +impl Vector { + pub fn test() {} +}