mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
rustdoc: Collect traits in scope for lang items
This commit is contained in:
parent
f838a425e3
commit
0da7adc828
@ -1032,13 +1032,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
|
||||
}
|
||||
|
||||
/// Iterates over the language items in the given crate.
|
||||
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
|
||||
tcx.arena.alloc_from_iter(
|
||||
self.root
|
||||
.lang_items
|
||||
.decode(self)
|
||||
.map(|(def_index, index)| (self.local_def_id(def_index), index)),
|
||||
)
|
||||
fn get_lang_items(self) -> impl Iterator<Item = (DefId, usize)> + 'a {
|
||||
self.root
|
||||
.lang_items
|
||||
.decode(self)
|
||||
.map(move |(def_index, index)| (self.local_def_id(def_index), index))
|
||||
}
|
||||
|
||||
/// Iterates over the diagnostic items in the given crate.
|
||||
|
@ -200,7 +200,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
|
||||
tcx.arena.alloc_slice(&result)
|
||||
}
|
||||
defined_lib_features => { cdata.get_lib_features(tcx) }
|
||||
defined_lang_items => { cdata.get_lang_items(tcx) }
|
||||
defined_lang_items => { tcx.arena.alloc_from_iter(cdata.get_lang_items()) }
|
||||
diagnostic_items => { cdata.get_diagnostic_items() }
|
||||
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
|
||||
|
||||
@ -501,6 +501,11 @@ impl CStore {
|
||||
) -> impl Iterator<Item = (DefId, DefId)> + '_ {
|
||||
self.get_crate_data(cnum).get_inherent_impls()
|
||||
}
|
||||
|
||||
/// Decodes all lang items in the crate (for rustdoc).
|
||||
pub fn lang_items_untracked(&self, cnum: CrateNum) -> impl Iterator<Item = DefId> + '_ {
|
||||
self.get_crate_data(cnum).get_lang_items().map(|(def_id, _)| def_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl CrateStore for CStore {
|
||||
|
@ -118,6 +118,7 @@ impl IntraLinkCrateLoader<'_, '_> {
|
||||
Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum));
|
||||
let all_inherent_impls =
|
||||
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));
|
||||
|
||||
// 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
|
||||
@ -141,6 +142,9 @@ impl IntraLinkCrateLoader<'_, '_> {
|
||||
self.add_traits_in_parent_scope(impl_def_id);
|
||||
}
|
||||
}
|
||||
for def_id in all_lang_items {
|
||||
self.add_traits_in_parent_scope(def_id);
|
||||
}
|
||||
|
||||
self.all_traits.extend(all_traits);
|
||||
self.all_trait_impls.extend(all_trait_impls.into_iter().map(|(_, def_id, _)| def_id));
|
||||
|
@ -0,0 +1,29 @@
|
||||
// no-prefer-dynamic
|
||||
|
||||
#![feature(lang_items)]
|
||||
|
||||
#![crate_type = "rlib"]
|
||||
#![no_std]
|
||||
|
||||
pub struct DerefsToF64(f64);
|
||||
|
||||
impl core::ops::Deref for DerefsToF64 {
|
||||
type Target = f64;
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.0
|
||||
}
|
||||
}
|
||||
|
||||
mod inner {
|
||||
#[lang = "f64_runtime"]
|
||||
impl f64 {
|
||||
/// [f64::clone]
|
||||
pub fn method() {}
|
||||
}
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
fn foo() {}
|
||||
|
||||
#[panic_handler]
|
||||
fn bar(_: &core::panic::PanicInfo) -> ! { loop {} }
|
11
src/test/rustdoc/intra-doc/extern-lang-item-impl.rs
Normal file
11
src/test/rustdoc/intra-doc/extern-lang-item-impl.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// Reexport of a structure that derefs to a type with lang item impls having doc links in their
|
||||
// comments. The doc link points to an associated item, so we check that traits in scope for that
|
||||
// link are populated.
|
||||
|
||||
// aux-build:extern-lang-item-impl-dep.rs
|
||||
|
||||
#![no_std]
|
||||
|
||||
extern crate extern_lang_item_impl_dep;
|
||||
|
||||
pub use extern_lang_item_impl_dep::DerefsToF64;
|
Loading…
Reference in New Issue
Block a user