Skip to content

Commit db30a25

Browse files
authored
Rollup merge of #103120 - petrochenkov:docice, r=GuillaumeGomez
rustdoc: Do not expect `doc(primitive)` modules to always exist The second commit fixes one more ICE by processing impls in crates loaded through the "load all `--extern`s" hack. Fixes #96288 Fixes #103028
2 parents 0602d64 + dd7411d commit db30a25

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ impl Res {
8080
}
8181
}
8282

83-
fn def_id(self, tcx: TyCtxt<'_>) -> DefId {
83+
fn def_id(self, tcx: TyCtxt<'_>) -> Option<DefId> {
8484
match self {
85-
Res::Def(_, id) => id,
86-
Res::Primitive(prim) => *PrimitiveType::primitive_locations(tcx).get(&prim).unwrap(),
85+
Res::Def(_, id) => Some(id),
86+
Res::Primitive(prim) => PrimitiveType::primitive_locations(tcx).get(&prim).copied(),
8787
}
8888
}
8989

@@ -1127,10 +1127,10 @@ impl LinkCollector<'_, '_> {
11271127
}
11281128
}
11291129

1130-
Some(ItemLink {
1130+
res.def_id(self.cx.tcx).map(|page_id| ItemLink {
11311131
link: ori_link.link.clone(),
11321132
link_text: link_text.clone(),
1133-
page_id: res.def_id(self.cx.tcx),
1133+
page_id,
11341134
fragment,
11351135
})
11361136
}

src/librustdoc/passes/collect_intra_doc_links/early.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ pub(crate) fn early_resolve_intra_doc_links(
4848
link_resolver.resolve_doc_links_local(&krate.attrs);
4949
link_resolver.process_module_children_or_reexports(CRATE_DEF_ID.to_def_id());
5050
visit::walk_crate(&mut link_resolver, krate);
51-
link_resolver.process_extern_impls();
5251

5352
// FIXME: somehow rustdoc is still missing crates even though we loaded all
5453
// 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(
5857
link_resolver.resolver.resolve_rustdoc_path(extern_name, TypeNS, parent_scope);
5958
}
6059

60+
link_resolver.process_extern_impls();
61+
6162
ResolverCaches {
6263
markdown_links: Some(link_resolver.markdown_links),
6364
doc_link_resolutions: link_resolver.doc_link_resolutions,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Crate tree without a `doc(primitive)` module for primitive type linked to by a doc link.
2+
3+
#![deny(rustdoc::broken_intra_doc_links)]
4+
#![feature(no_core, lang_items, rustc_attrs)]
5+
#![no_core]
6+
#![rustc_coherence_is_core]
7+
#![crate_type = "rlib"]
8+
9+
// @has no_doc_primitive/index.html
10+
//! A [`char`] and its [`char::len_utf8`].
11+
impl char {
12+
pub fn len_utf8(self) -> usize {
13+
42
14+
}
15+
}

0 commit comments

Comments
 (0)