Skip to content

Commit 066f01d

Browse files
committed
Auto merge of rust-lang#82960 - camelid:masked_crates, r=jyn514
Remove `masked_crates` from `clean::Crate` Previously, `masked_crates` existed both on `Cache` and on `clean::Crate`. During cache population, the `clean::Crate` version was `take`n and moved to `Cache`. This change removes the version on `clean::Crate` and instead directly mutates `Cache.masked_crates` to initialize it. This has the advantage of avoiding duplication and avoiding unnecessary allocation, as well as making the flow of information through rustdoc less confusing. The one downside I see is that `clean::utils::krate()` now uses the side effect of mutating `DocContext.cache` instead of returning the data directly, but it already mutated the `Cache` for other things (e.g., `deref_trait_did`) so it's not really new behavior. Also, `clean::utils::krate()` is only called once (and is meant to only be called once since it performs expensive and potentially destructive operations) so the mutation shouldn't be an issue. Follow-up to rust-lang#82018 (comment). cc `@jyn514`
2 parents f98721f + b7d91b0 commit 066f01d

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

src/librustdoc/clean/types.rs

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ crate struct Crate {
5757
// These are later on moved into `CACHEKEY`, leaving the map empty.
5858
// Only here so that they can be filtered through the rustdoc passes.
5959
crate external_traits: Rc<RefCell<FxHashMap<DefId, TraitWithExtraInfo>>>,
60-
crate masked_crates: FxHashSet<CrateNum>,
6160
crate collapsed: bool,
6261
}
6362

src/librustdoc/clean/utils.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use crate::clean::{
77
};
88
use crate::core::DocContext;
99

10-
use rustc_data_structures::fx::FxHashSet;
1110
use rustc_hir as hir;
1211
use rustc_hir::def::{DefKind, Res};
1312
use rustc_hir::def_id::{DefId, LOCAL_CRATE};
@@ -38,7 +37,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
3837
// Clean the crate, translating the entire librustc_ast AST to one that is
3938
// understood by rustdoc.
4039
let mut module = module.clean(cx);
41-
let mut masked_crates = FxHashSet::default();
4240

4341
match *module.kind {
4442
ItemKind::ModuleItem(ref module) => {
@@ -49,7 +47,7 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
4947
&& (it.attrs.has_doc_flag(sym::masked)
5048
|| cx.tcx.is_compiler_builtins(it.def_id.krate))
5149
{
52-
masked_crates.insert(it.def_id.krate);
50+
cx.cache.masked_crates.insert(it.def_id.krate);
5351
}
5452
}
5553
}
@@ -82,7 +80,6 @@ crate fn krate(cx: &mut DocContext<'_>) -> Crate {
8280
externs,
8381
primitives,
8482
external_traits: cx.external_traits.clone(),
85-
masked_crates,
8683
collapsed: false,
8784
}
8885
}

src/librustdoc/formats/cache.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,16 @@ crate struct Cache {
8989
/// This is stored in `Cache` so it doesn't need to be passed through all rustdoc functions.
9090
crate document_private: bool,
9191

92+
/// Crates marked with [`#[doc(masked)]`][doc_masked].
93+
///
94+
/// [doc_masked]: https://doc.rust-lang.org/nightly/unstable-book/language-features/doc-masked.html
95+
crate masked_crates: FxHashSet<CrateNum>,
96+
9297
// Private fields only used when initially crawling a crate to build a cache
9398
stack: Vec<String>,
9499
parent_stack: Vec<DefId>,
95100
parent_is_trait_impl: bool,
96101
stripped_mod: bool,
97-
masked_crates: FxHashSet<CrateNum>,
98102

99103
crate search_index: Vec<IndexItem>,
100104
crate deref_trait_did: Option<DefId>,
@@ -146,7 +150,6 @@ impl Cache {
146150
// Crawl the crate to build various caches used for the output
147151
debug!(?self.crate_version);
148152
self.traits = krate.external_traits.take();
149-
self.masked_crates = mem::take(&mut krate.masked_crates);
150153

151154
// Cache where all our extern crates are located
152155
// FIXME: this part is specific to HTML so it'd be nice to remove it from the common code

0 commit comments

Comments
 (0)