Skip to content

Commit b8c56fa

Browse files
committed
Auto merge of #93766 - petrochenkov:doclinkregr, r=camelid,GuillaumeGomez
rustdoc: Collect traits in scope for lang items Inherent impls on primitive types are not included in the list of all inherent impls in the crate (`inherent_impls_in_crate_untracked`), they are taken from the list of lang items instead, but such impls can also be inlined by rustdoc, e.g. if something derefs to a primitive type. r? `@camelid` Fixes #93698
2 parents feac2ec + 0da7adc commit b8c56fa

File tree

5 files changed

+55
-8
lines changed

5 files changed

+55
-8
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -1032,13 +1032,11 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10321032
}
10331033

10341034
/// Iterates over the language items in the given crate.
1035-
fn get_lang_items(self, tcx: TyCtxt<'tcx>) -> &'tcx [(DefId, usize)] {
1036-
tcx.arena.alloc_from_iter(
1037-
self.root
1038-
.lang_items
1039-
.decode(self)
1040-
.map(|(def_index, index)| (self.local_def_id(def_index), index)),
1041-
)
1035+
fn get_lang_items(self) -> impl Iterator<Item = (DefId, usize)> + 'a {
1036+
self.root
1037+
.lang_items
1038+
.decode(self)
1039+
.map(move |(def_index, index)| (self.local_def_id(def_index), index))
10421040
}
10431041

10441042
/// Iterates over the diagnostic items in the given crate.

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
200200
tcx.arena.alloc_slice(&result)
201201
}
202202
defined_lib_features => { cdata.get_lib_features(tcx) }
203-
defined_lang_items => { cdata.get_lang_items(tcx) }
203+
defined_lang_items => { tcx.arena.alloc_from_iter(cdata.get_lang_items()) }
204204
diagnostic_items => { cdata.get_diagnostic_items() }
205205
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
206206

@@ -501,6 +501,11 @@ impl CStore {
501501
) -> impl Iterator<Item = (DefId, DefId)> + '_ {
502502
self.get_crate_data(cnum).get_inherent_impls()
503503
}
504+
505+
/// Decodes all lang items in the crate (for rustdoc).
506+
pub fn lang_items_untracked(&self, cnum: CrateNum) -> impl Iterator<Item = DefId> + '_ {
507+
self.get_crate_data(cnum).get_lang_items().map(|(def_id, _)| def_id)
508+
}
504509
}
505510

506511
impl CrateStore for CStore {

src/librustdoc/passes/collect_intra_doc_links/early.rs

+4
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ impl IntraLinkCrateLoader<'_, '_> {
118118
Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum));
119119
let all_inherent_impls =
120120
Vec::from_iter(self.resolver.cstore().inherent_impls_in_crate_untracked(cnum));
121+
let all_lang_items = Vec::from_iter(self.resolver.cstore().lang_items_untracked(cnum));
121122

122123
// Querying traits in scope is expensive so we try to prune the impl and traits lists
123124
// using privacy, private traits and impls from other crates are never documented in
@@ -141,6 +142,9 @@ impl IntraLinkCrateLoader<'_, '_> {
141142
self.add_traits_in_parent_scope(impl_def_id);
142143
}
143144
}
145+
for def_id in all_lang_items {
146+
self.add_traits_in_parent_scope(def_id);
147+
}
144148

145149
self.all_traits.extend(all_traits);
146150
self.all_trait_impls.extend(all_trait_impls.into_iter().map(|(_, def_id, _)| def_id));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// no-prefer-dynamic
2+
3+
#![feature(lang_items)]
4+
5+
#![crate_type = "rlib"]
6+
#![no_std]
7+
8+
pub struct DerefsToF64(f64);
9+
10+
impl core::ops::Deref for DerefsToF64 {
11+
type Target = f64;
12+
fn deref(&self) -> &Self::Target {
13+
&self.0
14+
}
15+
}
16+
17+
mod inner {
18+
#[lang = "f64_runtime"]
19+
impl f64 {
20+
/// [f64::clone]
21+
pub fn method() {}
22+
}
23+
}
24+
25+
#[lang = "eh_personality"]
26+
fn foo() {}
27+
28+
#[panic_handler]
29+
fn bar(_: &core::panic::PanicInfo) -> ! { loop {} }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Reexport of a structure that derefs to a type with lang item impls having doc links in their
2+
// comments. The doc link points to an associated item, so we check that traits in scope for that
3+
// link are populated.
4+
5+
// aux-build:extern-lang-item-impl-dep.rs
6+
7+
#![no_std]
8+
9+
extern crate extern_lang_item_impl_dep;
10+
11+
pub use extern_lang_item_impl_dep::DerefsToF64;

0 commit comments

Comments
 (0)