Skip to content

Commit c754e82

Browse files
refactor: move access_levels into RenderInfo
1 parent 87760e5 commit c754e82

File tree

8 files changed

+19
-19
lines changed

8 files changed

+19
-19
lines changed

src/librustdoc/clean/blanket_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
6969
let real_name = name.clone().map(|name| Ident::from_str(&name));
7070
let param_env = self.cx.tcx.param_env(def_id);
7171
for &trait_def_id in self.cx.all_traits.iter() {
72-
if !self.cx.access_levels.borrow().is_doc_reachable(trait_def_id) ||
72+
if !self.cx.renderinfo.borrow().access_levels.is_doc_reachable(trait_def_id) ||
7373
self.cx.generated_synthetics
7474
.borrow_mut()
7575
.get(&(def_id, trait_def_id))

src/librustdoc/clean/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
297297
// reachable in rustdoc generated documentation
298298
if !did.is_local() {
299299
if let Some(traitref) = associated_trait {
300-
if !cx.access_levels.borrow().is_doc_reachable(traitref.def_id) {
300+
if !cx.renderinfo.borrow().access_levels.is_doc_reachable(traitref.def_id) {
301301
return
302302
}
303303
}
@@ -318,7 +318,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
318318
// reachable in rustdoc generated documentation
319319
if !did.is_local() {
320320
if let Some(did) = for_.def_id() {
321-
if !cx.access_levels.borrow().is_doc_reachable(did) {
321+
if !cx.renderinfo.borrow().access_levels.is_doc_reachable(did) {
322322
return
323323
}
324324
}

src/librustdoc/clean/mod.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use syntax::symbol::InternedString;
2828
use syntax_pos::{self, DUMMY_SP, Pos, FileName};
2929

3030
use rustc::mir::interpret::ConstValue;
31-
use rustc::middle::privacy::AccessLevels;
3231
use rustc::middle::resolve_lifetime as rl;
3332
use rustc::ty::fold::TypeFolder;
3433
use rustc::middle::lang_items;
@@ -135,7 +134,6 @@ pub struct Crate {
135134
pub module: Option<Item>,
136135
pub externs: Vec<(CrateNum, ExternalCrate)>,
137136
pub primitives: Vec<(DefId, PrimitiveType, Attributes)>,
138-
pub access_levels: Arc<AccessLevels<DefId>>,
139137
// These are later on moved into `CACHEKEY`, leaving the map empty.
140138
// Only here so that they can be filtered through the rustdoc passes.
141139
pub external_traits: FxHashMap<DefId, Trait>,
@@ -216,7 +214,6 @@ impl<'a, 'tcx, 'rcx, 'cstore> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tc
216214
module: Some(module),
217215
externs,
218216
primitives,
219-
access_levels: Arc::new(Default::default()),
220217
external_traits: Default::default(),
221218
masked_crates,
222219
}
@@ -2433,7 +2430,7 @@ impl Clean<Type> for hir::Ty {
24332430
if let Def::TyAlias(def_id) = path.def {
24342431
// Substitute private type aliases
24352432
if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
2436-
if !cx.access_levels.borrow().is_exported(def_id) {
2433+
if !cx.renderinfo.borrow().access_levels.is_exported(def_id) {
24372434
alias = Some(&cx.tcx.hir.expect_item(node_id).node);
24382435
}
24392436
}

src/librustdoc/core.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use std::cell::RefCell;
4141
use std::mem;
4242
use rustc_data_structures::sync::{self, Lrc};
4343
use std::rc::Rc;
44-
use std::sync::Arc;
4544
use std::path::PathBuf;
4645

4746
use visit_ast::RustdocVisitor;
@@ -64,8 +63,6 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a, 'cstore: 'rcx> {
6463
// Note that external items for which `doc(hidden)` applies to are shown as
6564
// non-reachable while local items aren't. This is because we're reusing
6665
// the access levels from crateanalysis.
67-
/// Later on moved into `clean::Crate`
68-
pub access_levels: RefCell<AccessLevels<DefId>>,
6966
/// Later on moved into `html::render::CACHE_KEY`
7067
pub renderinfo: RefCell<RenderInfo>,
7168
/// Later on moved through `clean::Crate` into `html::render::CACHE_KEY`
@@ -509,15 +506,17 @@ pub fn run_core(search_paths: SearchPaths,
509506
clean::path_to_def(&tcx, &["core", "marker", "Send"])
510507
};
511508

509+
let mut renderinfo = RenderInfo::default();
510+
renderinfo.access_levels = access_levels;
511+
512512
let ctxt = DocContext {
513513
tcx,
514514
resolver: &resolver,
515515
crate_name,
516516
cstore: cstore.clone(),
517-
access_levels: RefCell::new(access_levels),
518517
external_traits: Default::default(),
519518
active_extern_traits: Default::default(),
520-
renderinfo: Default::default(),
519+
renderinfo: RefCell::new(renderinfo),
521520
ty_substs: Default::default(),
522521
lt_substs: Default::default(),
523522
impl_trait_bounds: Default::default(),
@@ -600,7 +599,6 @@ pub fn run_core(search_paths: SearchPaths,
600599

601600
ctxt.sess().abort_if_errors();
602601

603-
krate.access_levels = Arc::new(ctxt.access_levels.into_inner());
604602
krate.external_traits = ctxt.external_traits.into_inner();
605603

606604
(krate, ctxt.renderinfo.into_inner(), passes)

src/librustdoc/html/render.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub struct Cache {
313313
// Note that external items for which `doc(hidden)` applies to are shown as
314314
// non-reachable while local items aren't. This is because we're reusing
315315
// the access levels from crateanalysis.
316-
pub access_levels: Arc<AccessLevels<DefId>>,
316+
pub access_levels: AccessLevels<DefId>,
317317

318318
/// The version of the crate being documented, if given from the `--crate-version` flag.
319319
pub crate_version: Option<String>,
@@ -359,6 +359,7 @@ pub struct RenderInfo {
359359
pub external_paths: ::core::ExternalPaths,
360360
pub external_typarams: FxHashMap<DefId, String>,
361361
pub exact_paths: FxHashMap<DefId, Vec<String>>,
362+
pub access_levels: AccessLevels<DefId>,
362363
pub deref_trait_did: Option<DefId>,
363364
pub deref_mut_trait_did: Option<DefId>,
364365
pub owned_box_did: Option<DefId>,
@@ -578,6 +579,7 @@ pub fn run(mut krate: clean::Crate,
578579
external_paths,
579580
external_typarams,
580581
exact_paths,
582+
access_levels,
581583
deref_trait_did,
582584
deref_mut_trait_did,
583585
owned_box_did,
@@ -600,7 +602,7 @@ pub fn run(mut krate: clean::Crate,
600602
extern_locations: FxHashMap(),
601603
primitive_locations: FxHashMap(),
602604
stripped_mod: false,
603-
access_levels: krate.access_levels.clone(),
605+
access_levels,
604606
crate_version: krate.version.take(),
605607
orphan_impl_items: Vec::new(),
606608
orphan_trait_impls: Vec::new(),

src/librustdoc/passes/strip_private.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub const STRIP_PRIVATE: Pass =
2525
pub fn strip_private(mut krate: clean::Crate, cx: &DocContext) -> clean::Crate {
2626
// This stripper collects all *retained* nodes.
2727
let mut retained = DefIdSet();
28-
let access_levels = cx.access_levels.borrow().clone();
28+
let access_levels = cx.renderinfo.borrow().access_levels.clone();
2929

3030
// strip all private items
3131
{

src/librustdoc/visit_ast.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,10 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
269269
Def::Enum(did) |
270270
Def::ForeignTy(did) |
271271
Def::TyAlias(did) if !self_is_hidden => {
272-
self.cx.access_levels.borrow_mut().map.insert(did, AccessLevel::Public);
272+
self.cx.renderinfo
273+
.borrow_mut()
274+
.access_levels.map
275+
.insert(did, AccessLevel::Public);
273276
},
274277
Def::Mod(did) => if !self_is_hidden {
275278
::visit_lib::LibEmbargoVisitor::new(self.cx).visit_mod(did);
@@ -284,7 +287,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
284287
Some(n) => n, None => return false
285288
};
286289

287-
let is_private = !self.cx.access_levels.borrow().is_public(def_did);
290+
let is_private = !self.cx.renderinfo.borrow().access_levels.is_public(def_did);
288291
let is_hidden = inherits_doc_hidden(self.cx, def_node_id);
289292

290293
// Only inline if requested or if the item would otherwise be stripped

src/librustdoc/visit_lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> LibEmbargoVisitor<'a, 'tcx, 'rcx, 'cstore> {
3838
) -> LibEmbargoVisitor<'a, 'tcx, 'rcx, 'cstore> {
3939
LibEmbargoVisitor {
4040
cx,
41-
access_levels: cx.access_levels.borrow_mut(),
41+
access_levels: RefMut::map(cx.renderinfo.borrow_mut(), |ri| &mut ri.access_levels),
4242
prev_level: Some(AccessLevel::Public),
4343
visited_mods: FxHashSet()
4444
}

0 commit comments

Comments
 (0)