From c65f3db2d947a616c9c50ee6ba72d40141a49e3e Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 16 Oct 2022 20:39:53 +0400 Subject: [PATCH 1/2] rustdoc: Do not expect `doc(primitive)` modules to always exist --- src/librustdoc/passes/collect_intra_doc_links.rs | 10 +++++----- src/test/rustdoc/intra-doc/no-doc-primitive.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) create mode 100644 src/test/rustdoc/intra-doc/no-doc-primitive.rs diff --git a/src/librustdoc/passes/collect_intra_doc_links.rs b/src/librustdoc/passes/collect_intra_doc_links.rs index 3beda708bf2..3513c13d522 100644 --- a/src/librustdoc/passes/collect_intra_doc_links.rs +++ b/src/librustdoc/passes/collect_intra_doc_links.rs @@ -80,10 +80,10 @@ impl Res { } } - fn def_id(self, tcx: TyCtxt<'_>) -> DefId { + fn def_id(self, tcx: TyCtxt<'_>) -> Option { match self { - Res::Def(_, id) => id, - Res::Primitive(prim) => *PrimitiveType::primitive_locations(tcx).get(&prim).unwrap(), + Res::Def(_, id) => Some(id), + Res::Primitive(prim) => PrimitiveType::primitive_locations(tcx).get(&prim).copied(), } } @@ -1127,10 +1127,10 @@ impl LinkCollector<'_, '_> { } } - Some(ItemLink { + res.def_id(self.cx.tcx).map(|page_id| ItemLink { link: ori_link.link.clone(), link_text: link_text.clone(), - page_id: res.def_id(self.cx.tcx), + page_id, fragment, }) } diff --git a/src/test/rustdoc/intra-doc/no-doc-primitive.rs b/src/test/rustdoc/intra-doc/no-doc-primitive.rs new file mode 100644 index 00000000000..e5eba1d8d48 --- /dev/null +++ b/src/test/rustdoc/intra-doc/no-doc-primitive.rs @@ -0,0 +1,15 @@ +// Crate tree without a `doc(primitive)` module for primitive type linked to by a doc link. + +#![deny(rustdoc::broken_intra_doc_links)] +#![feature(no_core, lang_items, rustc_attrs)] +#![no_core] +#![rustc_coherence_is_core] +#![crate_type = "rlib"] + +// @has no_doc_primitive/index.html +//! A [`char`] and its [`char::len_utf8`]. +impl char { + pub fn len_utf8(self) -> usize { + 42 + } +} From dd7411d84868e415a88f12e5401abc29c257f3a4 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sun, 16 Oct 2022 21:51:13 +0400 Subject: [PATCH 2/2] rustdoc: Process extern impls in all loaded crates including those loaded through hacks. --- src/librustdoc/passes/collect_intra_doc_links/early.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/passes/collect_intra_doc_links/early.rs b/src/librustdoc/passes/collect_intra_doc_links/early.rs index 38cfd7a27dd..50dc26d768c 100644 --- a/src/librustdoc/passes/collect_intra_doc_links/early.rs +++ b/src/librustdoc/passes/collect_intra_doc_links/early.rs @@ -48,7 +48,6 @@ pub(crate) fn early_resolve_intra_doc_links( link_resolver.resolve_doc_links_local(&krate.attrs); link_resolver.process_module_children_or_reexports(CRATE_DEF_ID.to_def_id()); visit::walk_crate(&mut link_resolver, krate); - link_resolver.process_extern_impls(); // FIXME: somehow rustdoc is still missing crates even though we loaded all // the known necessary crates. Load them all unconditionally until we find a way to fix this. @@ -58,6 +57,8 @@ pub(crate) fn early_resolve_intra_doc_links( link_resolver.resolver.resolve_rustdoc_path(extern_name, TypeNS, parent_scope); } + link_resolver.process_extern_impls(); + ResolverCaches { markdown_links: Some(link_resolver.markdown_links), doc_link_resolutions: link_resolver.doc_link_resolutions,