Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit c65f3db

Browse files
committed
rustdoc: Do not expect doc(primitive) modules to always exist
1 parent 8be3ce9 commit c65f3db

File tree

2 files changed

+20
-5
lines changed

2 files changed

+20
-5
lines changed

src/librustdoc/passes/collect_intra_doc_links.rs

Lines changed: 5 additions & 5 deletions
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
}
Lines changed: 15 additions & 0 deletions
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)