Skip to content

Commit ee62514

Browse files
committed
fix rustdoc wrt builtin impls switch
1 parent a6153e8 commit ee62514

File tree

8 files changed

+35
-23
lines changed

8 files changed

+35
-23
lines changed

compiler/rustc_metadata/src/rmeta/decoder.rs

+14-5
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
10331033
}
10341034

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

10431045
/// Iterates over the diagnostic items in the given crate.
@@ -1343,6 +1345,13 @@ impl<'a, 'tcx> CrateMetadataRef<'a> {
13431345
})
13441346
}
13451347

1348+
fn get_all_incoherent_impls(self) -> impl Iterator<Item = DefId> + 'a {
1349+
self.cdata
1350+
.incoherent_impls
1351+
.values()
1352+
.flat_map(move |impls| impls.decode(self).map(move |idx| self.local_def_id(idx)))
1353+
}
1354+
13461355
fn get_incoherent_impls(self, tcx: TyCtxt<'tcx>, simp: SimplifiedType) -> &'tcx [DefId] {
13471356
if let Some(impls) = self.cdata.incoherent_impls.get(&simp) {
13481357
tcx.arena.alloc_from_iter(impls.decode(self).map(|idx| self.local_def_id(idx)))

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ provide! { <'tcx> tcx, def_id, other, cdata,
223223
tcx.arena.alloc_slice(&result)
224224
}
225225
defined_lib_features => { cdata.get_lib_features(tcx) }
226-
defined_lang_items => { tcx.arena.alloc_from_iter(cdata.get_lang_items()) }
226+
defined_lang_items => { cdata.get_lang_items(tcx) }
227227
diagnostic_items => { cdata.get_diagnostic_items() }
228228
missing_lang_items => { cdata.get_missing_lang_items(tcx) }
229229

@@ -523,9 +523,12 @@ impl CStore {
523523
self.get_crate_data(cnum).get_inherent_impls()
524524
}
525525

526-
/// Decodes all lang items in the crate (for rustdoc).
527-
pub fn lang_items_untracked(&self, cnum: CrateNum) -> impl Iterator<Item = DefId> + '_ {
528-
self.get_crate_data(cnum).get_lang_items().map(|(def_id, _)| def_id)
526+
/// Decodes all incoherent inherent impls in the crate (for rustdoc).
527+
pub fn incoherent_impls_in_crate_untracked(
528+
&self,
529+
cnum: CrateNum,
530+
) -> impl Iterator<Item = DefId> + '_ {
531+
self.get_crate_data(cnum).get_all_incoherent_impls()
529532
}
530533
}
531534

src/librustdoc/passes/collect_intra_doc_links/early.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ impl IntraLinkCrateLoader<'_, '_> {
113113
Vec::from_iter(self.resolver.cstore().trait_impls_in_crate_untracked(cnum));
114114
let all_inherent_impls =
115115
Vec::from_iter(self.resolver.cstore().inherent_impls_in_crate_untracked(cnum));
116-
let all_lang_items = Vec::from_iter(self.resolver.cstore().lang_items_untracked(cnum));
116+
let all_incoherent_impls =
117+
Vec::from_iter(self.resolver.cstore().incoherent_impls_in_crate_untracked(cnum));
117118

118119
// Querying traits in scope is expensive so we try to prune the impl and traits lists
119120
// using privacy, private traits and impls from other crates are never documented in
@@ -137,7 +138,7 @@ impl IntraLinkCrateLoader<'_, '_> {
137138
self.add_traits_in_parent_scope(impl_def_id);
138139
}
139140
}
140-
for def_id in all_lang_items {
141+
for def_id in all_incoherent_impls {
141142
self.add_traits_in_parent_scope(def_id);
142143
}
143144

src/test/rustdoc/intra-doc/auxiliary/extern-lang-item-impl-dep.rs renamed to src/test/rustdoc/intra-doc/auxiliary/extern-builtin-type-impl-dep.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// no-prefer-dynamic
22

3-
#![feature(lang_items)]
4-
3+
#![feature(lang_items, rustc_attrs)]
54
#![crate_type = "rlib"]
65
#![no_std]
76

@@ -15,9 +14,9 @@ impl core::ops::Deref for DerefsToF64 {
1514
}
1615

1716
mod inner {
18-
#[lang = "f64_runtime"]
1917
impl f64 {
2018
/// [f64::clone]
19+
#[rustc_allow_incoherent_impl]
2120
pub fn method() {}
2221
}
2322
}

src/test/rustdoc/intra-doc/auxiliary/my-core.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
#![feature(no_core, lang_items, rustdoc_internals)]
1+
#![feature(no_core, lang_items, rustdoc_internals, rustc_attrs)]
22
#![no_core]
3+
#![rustc_coherence_is_core]
34
#![crate_type="rlib"]
45

56
#[doc(primitive = "char")]
67
/// Some char docs
78
mod char {}
89

9-
#[lang = "char"]
1010
impl char {
1111
pub fn len_utf8(self) -> usize {
1212
42

src/test/rustdoc/intra-doc/extern-lang-item-impl.rs renamed to src/test/rustdoc/intra-doc/extern-builtin-type-impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
// comments. The doc link points to an associated item, so we check that traits in scope for that
33
// link are populated.
44

5-
// aux-build:extern-lang-item-impl-dep.rs
5+
// aux-build:extern-builtin-type-impl-dep.rs
66

77
#![no_std]
88

9-
extern crate extern_lang_item_impl_dep;
9+
extern crate extern_builtin_type_impl_dep;
1010

11-
pub use extern_lang_item_impl_dep::DerefsToF64;
11+
pub use extern_builtin_type_impl_dep::DerefsToF64;

src/test/rustdoc/intra-doc/prim-methods-local.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![deny(rustdoc::broken_intra_doc_links)]
2-
#![feature(no_core, lang_items, rustdoc_internals)]
2+
#![feature(no_core, lang_items, rustc_attrs, rustdoc_internals)]
33
#![no_core]
4+
#![rustc_coherence_is_core]
45
#![crate_type = "rlib"]
56

67
// @has prim_methods_local/index.html
@@ -12,7 +13,6 @@
1213
#[doc(primitive = "char")]
1314
mod char {}
1415

15-
#[lang = "char"]
1616
impl char {
1717
pub fn len_utf8(self) -> usize {
1818
42

src/test/rustdoc/issue-23511.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#![feature(lang_items)]
1+
#![feature(rustc_attrs)]
22
#![feature(rustdoc_internals)]
33
#![no_std]
44

55
pub mod str {
66
#![doc(primitive = "str")]
77

8-
#[lang = "str_alloc"]
98
impl str {
109
// @has search-index.js foo
10+
#[rustc_allow_incoherent_impl]
1111
pub fn foo(&self) {}
1212
}
1313
}

0 commit comments

Comments
 (0)