fix rustdoc wrt builtin impls switch

This commit is contained in:
lcnr 2022-03-18 17:02:32 +01:00
parent a6153e8218
commit ee62514b16
8 changed files with 35 additions and 23 deletions

View File

@ -1033,11 +1033,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
} }
/// Iterates over the language items in the given crate. /// Iterates over the language items in the given crate.
fn get_lang_items(self) -> impl Iterator<Item = (DefId, usize)> + 'a { fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
self.root tcx.arena.alloc_from_iter(
.lang_items self.root
.decode(self) .lang_items
.map(move |(def_index, index)| (self.local_def_id(def_index), index)) .decode(self)
.map(move |(def_index, index)| (self.local_def_id(def_index), index)),
)
} }
/// Iterates over the diagnostic items in the given crate. /// Iterates over the diagnostic items in the given crate.
@ -1343,6 +1345,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
}) })
} }
fn get_all_incoherent_impls(self) -> impl Iterator<Item = DefId> + 'a {
self.cdata
.incoherent_impls
.values()
.flat_map(move |impls| impls.decode(self).map(move |idx| self.local_def_id(idx)))
}
fn get_incoherent_impls(self, tcx: TyCtxt<'tcx>, simp: SimplifiedType) -> &'tcx [DefId] { fn get_incoherent_impls(self, tcx: TyCtxt<'tcx>, simp: SimplifiedType) -> &'tcx [DefId] {
if let Some(impls) = self.cdata.incoherent_impls.get(&simp) { if let Some(impls) = self.cdata.incoherent_impls.get(&simp) {
tcx.arena.alloc_from_iter(impls.decode(self).map(|idx| self.local_def_id(idx))) tcx.arena.alloc_from_iter(impls.decode(self).map(|idx| self.local_def_id(idx)))

View File

@ -223,7 +223,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
tcx.arena.alloc_slice(&result) tcx.arena.alloc_slice(&result)
} }
defined_lib_features => { cdata.get_lib_features(tcx) } defined_lib_features => { cdata.get_lib_features(tcx) }
defined_lang_items => { tcx.arena.alloc_from_iter(cdata.get_lang_items()) } defined_lang_items => { cdata.get_lang_items(tcx) }
diagnostic_items => { cdata.get_diagnostic_items() } diagnostic_items => { cdata.get_diagnostic_items() }
missing_lang_items => { cdata.get_missing_lang_items(tcx) } missing_lang_items => { cdata.get_missing_lang_items(tcx) }
@ -523,9 +523,12 @@ impl CStore {
self.get_crate_data(cnum).get_inherent_impls() self.get_crate_data(cnum).get_inherent_impls()
} }
/// Decodes all lang items in the crate (for rustdoc). /// Decodes all incoherent inherent impls in the crate (for rustdoc).
pub fn lang_items_untracked(&self, cnum: CrateNum) -> impl Iterator<Item = DefId> + '_ { pub fn incoherent_impls_in_crate_untracked(
self.get_crate_data(cnum).get_lang_items().map(|(def_id, _)| def_id) &self,
cnum: CrateNum,
) -> impl Iterator<Item = DefId> + '_ {
self.get_crate_data(cnum).get_all_incoherent_impls()
} }
} }

View File

@ -113,7 +113,8 @@ impl IntraLinkCrateLoader<'_, '_> {
Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum)); Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum));
let all_inherent_impls = let all_inherent_impls =
Vec::from_iter(self.resolver.cstore().inherent_impls_in_crate_untracked(cnum)); Vec::from_iter(self.resolver.cstore().inherent_impls_in_crate_untracked(cnum));
let all_lang_items = Vec::from_iter(self.resolver.cstore().lang_items_untracked(cnum)); let all_incoherent_impls =
Vec::from_iter(self.resolver.cstore().incoherent_impls_in_crate_untracked(cnum));
// Querying traits in scope is expensive so we try to prune the impl and traits lists // Querying traits in scope is expensive so we try to prune the impl and traits lists
// using privacy, private traits and impls from other crates are never documented in // using privacy, private traits and impls from other crates are never documented in
@ -137,7 +138,7 @@ impl IntraLinkCrateLoader<'_, '_> {
self.add_traits_in_parent_scope(impl_def_id); self.add_traits_in_parent_scope(impl_def_id);
} }
} }
for def_id in all_lang_items { for def_id in all_incoherent_impls {
self.add_traits_in_parent_scope(def_id); self.add_traits_in_parent_scope(def_id);
} }

View File

@ -1,7 +1,6 @@
// no-prefer-dynamic // no-prefer-dynamic
#![feature(lang_items)] #![feature(lang_items, rustc_attrs)]
#![crate_type = "rlib"] #![crate_type = "rlib"]
#![no_std] #![no_std]
@ -15,9 +14,9 @@ impl core::ops::Deref for DerefsToF64 {
} }
mod inner { mod inner {
#[lang = "f64_runtime"]
impl f64 { impl f64 {
/// [f64::clone] /// [f64::clone]
#[rustc_allow_incoherent_impl]
pub fn method() {} pub fn method() {}
} }
} }

View File

@ -1,12 +1,12 @@
#![feature(no_core, lang_items, rustdoc_internals)] #![feature(no_core, lang_items, rustdoc_internals, rustc_attrs)]
#![no_core] #![no_core]
#![rustc_coherence_is_core]
#![crate_type="rlib"] #![crate_type="rlib"]
#[doc(primitive = "char")] #[doc(primitive = "char")]
/// Some char docs /// Some char docs
mod char {} mod char {}
#[lang = "char"]
impl char { impl char {
pub fn len_utf8(self) -> usize { pub fn len_utf8(self) -> usize {
42 42

View File

@ -2,10 +2,10 @@
// comments. The doc link points to an associated item, so we check that traits in scope for that // comments. The doc link points to an associated item, so we check that traits in scope for that
// link are populated. // link are populated.
// aux-build:extern-lang-item-impl-dep.rs // aux-build:extern-builtin-type-impl-dep.rs
#![no_std] #![no_std]
extern crate extern_lang_item_impl_dep; extern crate extern_builtin_type_impl_dep;
pub use extern_lang_item_impl_dep::DerefsToF64; pub use extern_builtin_type_impl_dep::DerefsToF64;

View File

@ -1,6 +1,7 @@
#![deny(rustdoc::broken_intra_doc_links)] #![deny(rustdoc::broken_intra_doc_links)]
#![feature(no_core, lang_items, rustdoc_internals)] #![feature(no_core, lang_items, rustc_attrs, rustdoc_internals)]
#![no_core] #![no_core]
#![rustc_coherence_is_core]
#![crate_type = "rlib"] #![crate_type = "rlib"]
// @has prim_methods_local/index.html // @has prim_methods_local/index.html
@ -12,7 +13,6 @@
#[doc(primitive = "char")] #[doc(primitive = "char")]
mod char {} mod char {}
#[lang = "char"]
impl char { impl char {
pub fn len_utf8(self) -> usize { pub fn len_utf8(self) -> usize {
42 42

View File

@ -1,13 +1,13 @@
#![feature(lang_items)] #![feature(rustc_attrs)]
#![feature(rustdoc_internals)] #![feature(rustdoc_internals)]
#![no_std] #![no_std]
pub mod str { pub mod str {
#![doc(primitive = "str")] #![doc(primitive = "str")]
#[lang = "str_alloc"]
impl str { impl str {
// @has search-index.js foo // @has search-index.js foo
#[rustc_allow_incoherent_impl]
pub fn foo(&self) {} pub fn foo(&self) {}
} }
} }