From 071d8b14dab01f636aa4c8ec707a59a00bfa356d Mon Sep 17 00:00:00 2001 From: Hannah McLaughlin Date: Sun, 15 Nov 2020 20:45:52 +0000 Subject: [PATCH 1/3] Fix rustdoc: Referencing methods on extern_types does not resolve #78777: handle DefKind::ForeignTy variant --- src/librustdoc/passes/collect_intra_doc_links.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 895414b1d7e4c..fd09ba04b3db9 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -492,7 +492,14 @@ impl<'a, 'tcx> LinkCollector<'a, 'tcx> { Res::PrimTy(prim) => Some( self.resolve_primitive_associated_item(prim, ns, module_id, item_name, item_str), ), - Res::Def(DefKind::Struct | DefKind::Union | DefKind::Enum | DefKind::TyAlias, did) => { + Res::Def( + DefKind::Struct + | DefKind::Union + | DefKind::Enum + | DefKind::TyAlias + | DefKind::ForeignTy, + did, + ) => { debug!("looking for associated item named {} for item {:?}", item_name, did); // Checks if item_name belongs to `impl SomeItem` let assoc_item = cx From d38dbcb19f6ef1c5ffcf7869767674ef3d6d045f Mon Sep 17 00:00:00 2001 From: Hannah McLaughlin Date: Sun, 15 Nov 2020 21:14:00 +0000 Subject: [PATCH 2/3] Improve error message when we try to get_type on something that does not have a type --- compiler/rustc_metadata/src/rmeta/decoder.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index a1df1a63fc58d..19340dd51de14 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -947,7 +947,12 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { } fn get_type(&self, id: DefIndex, tcx: TyCtxt<'tcx>) -> Ty<'tcx> { - self.root.tables.ty.get(self, id).unwrap().decode((self, tcx)) + self.root + .tables + .ty + .get(self, id) + .unwrap_or_else(|| panic!("Not a type: {:?}", id)) + .decode((self, tcx)) } fn get_stability(&self, id: DefIndex) -> Option { From 32cd4bc790ae8a4b0d7105e2a70de90616a5a621 Mon Sep 17 00:00:00 2001 From: Hannah McLaughlin Date: Wed, 18 Nov 2020 22:14:58 +0000 Subject: [PATCH 3/3] Add test --- src/test/rustdoc/intra-link-extern-type.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/test/rustdoc/intra-link-extern-type.rs diff --git a/src/test/rustdoc/intra-link-extern-type.rs b/src/test/rustdoc/intra-link-extern-type.rs new file mode 100644 index 0000000000000..418e0d91ea7ef --- /dev/null +++ b/src/test/rustdoc/intra-link-extern-type.rs @@ -0,0 +1,18 @@ +#![feature(extern_types)] + +extern { + pub type ExternType; +} + +impl ExternType { + pub fn f(&self) { + + } +} + +// @has 'intra_link_extern_type/foreigntype.ExternType.html' +// @has 'intra_link_extern_type/fn.links_to_extern_type.html' \ +// 'href="../intra_link_extern_type/foreigntype.ExternType.html#method.f"' +/// See also [ExternType::f] +pub fn links_to_extern_type() { +}