rustdoc: Do not expect doc(primitive) modules to always exist

This commit is contained in:
Vadim Petrochenkov 2022-10-16 20:39:53 +04:00
parent 8be3ce9056
commit c65f3db2d9
2 changed files with 20 additions and 5 deletions

View File

@ -80,10 +80,10 @@ impl Res {
}
}
fn def_id(self, tcx: TyCtxt<'_>) -> DefId {
fn def_id(self, tcx: TyCtxt<'_>) -> Option<DefId> {
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,
})
}

View File

@ -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
}
}