Skip to content

Commit

Permalink
refactor: move access_levels into RenderInfo
Browse files Browse the repository at this point in the history
  • Loading branch information
QuietMisdreavus committed Sep 20, 2018
1 parent 87760e5 commit c754e82
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/librustdoc/clean/blanket_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> BlanketImplFinder <'a, 'tcx, 'rcx, 'cstore> {
let real_name = name.clone().map(|name| Ident::from_str(&name));
let param_env = self.cx.tcx.param_env(def_id);
for &trait_def_id in self.cx.all_traits.iter() {
if !self.cx.access_levels.borrow().is_doc_reachable(trait_def_id) ||
if !self.cx.renderinfo.borrow().access_levels.is_doc_reachable(trait_def_id) ||
self.cx.generated_synthetics
.borrow_mut()
.get(&(def_id, trait_def_id))
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
// reachable in rustdoc generated documentation
if !did.is_local() {
if let Some(traitref) = associated_trait {
if !cx.access_levels.borrow().is_doc_reachable(traitref.def_id) {
if !cx.renderinfo.borrow().access_levels.is_doc_reachable(traitref.def_id) {
return
}
}
Expand All @@ -318,7 +318,7 @@ pub fn build_impl(cx: &DocContext, did: DefId, ret: &mut Vec<clean::Item>) {
// reachable in rustdoc generated documentation
if !did.is_local() {
if let Some(did) = for_.def_id() {
if !cx.access_levels.borrow().is_doc_reachable(did) {
if !cx.renderinfo.borrow().access_levels.is_doc_reachable(did) {
return
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use syntax::symbol::InternedString;
use syntax_pos::{self, DUMMY_SP, Pos, FileName};

use rustc::mir::interpret::ConstValue;
use rustc::middle::privacy::AccessLevels;
use rustc::middle::resolve_lifetime as rl;
use rustc::ty::fold::TypeFolder;
use rustc::middle::lang_items;
Expand Down Expand Up @@ -135,7 +134,6 @@ pub struct Crate {
pub module: Option<Item>,
pub externs: Vec<(CrateNum, ExternalCrate)>,
pub primitives: Vec<(DefId, PrimitiveType, Attributes)>,
pub access_levels: Arc<AccessLevels<DefId>>,
// These are later on moved into `CACHEKEY`, leaving the map empty.
// Only here so that they can be filtered through the rustdoc passes.
pub external_traits: FxHashMap<DefId, Trait>,
Expand Down Expand Up @@ -216,7 +214,6 @@ impl<'a, 'tcx, 'rcx, 'cstore> Clean<Crate> for visit_ast::RustdocVisitor<'a, 'tc
module: Some(module),
externs,
primitives,
access_levels: Arc::new(Default::default()),
external_traits: Default::default(),
masked_crates,
}
Expand Down Expand Up @@ -2433,7 +2430,7 @@ impl Clean<Type> for hir::Ty {
if let Def::TyAlias(def_id) = path.def {
// Substitute private type aliases
if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
if !cx.access_levels.borrow().is_exported(def_id) {
if !cx.renderinfo.borrow().access_levels.is_exported(def_id) {
alias = Some(&cx.tcx.hir.expect_item(node_id).node);
}
}
Expand Down
10 changes: 4 additions & 6 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ use std::cell::RefCell;
use std::mem;
use rustc_data_structures::sync::{self, Lrc};
use std::rc::Rc;
use std::sync::Arc;
use std::path::PathBuf;

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

let mut renderinfo = RenderInfo::default();
renderinfo.access_levels = access_levels;

let ctxt = DocContext {
tcx,
resolver: &resolver,
crate_name,
cstore: cstore.clone(),
access_levels: RefCell::new(access_levels),
external_traits: Default::default(),
active_extern_traits: Default::default(),
renderinfo: Default::default(),
renderinfo: RefCell::new(renderinfo),
ty_substs: Default::default(),
lt_substs: Default::default(),
impl_trait_bounds: Default::default(),
Expand Down Expand Up @@ -600,7 +599,6 @@ pub fn run_core(search_paths: SearchPaths,

ctxt.sess().abort_if_errors();

krate.access_levels = Arc::new(ctxt.access_levels.into_inner());
krate.external_traits = ctxt.external_traits.into_inner();

(krate, ctxt.renderinfo.into_inner(), passes)
Expand Down
6 changes: 4 additions & 2 deletions src/librustdoc/html/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ pub struct Cache {
// Note that external items for which `doc(hidden)` applies to are shown as
// non-reachable while local items aren't. This is because we're reusing
// the access levels from crateanalysis.
pub access_levels: Arc<AccessLevels<DefId>>,
pub access_levels: AccessLevels<DefId>,

/// The version of the crate being documented, if given from the `--crate-version` flag.
pub crate_version: Option<String>,
Expand Down Expand Up @@ -359,6 +359,7 @@ pub struct RenderInfo {
pub external_paths: ::core::ExternalPaths,
pub external_typarams: FxHashMap<DefId, String>,
pub exact_paths: FxHashMap<DefId, Vec<String>>,
pub access_levels: AccessLevels<DefId>,
pub deref_trait_did: Option<DefId>,
pub deref_mut_trait_did: Option<DefId>,
pub owned_box_did: Option<DefId>,
Expand Down Expand Up @@ -578,6 +579,7 @@ pub fn run(mut krate: clean::Crate,
external_paths,
external_typarams,
exact_paths,
access_levels,
deref_trait_did,
deref_mut_trait_did,
owned_box_did,
Expand All @@ -600,7 +602,7 @@ pub fn run(mut krate: clean::Crate,
extern_locations: FxHashMap(),
primitive_locations: FxHashMap(),
stripped_mod: false,
access_levels: krate.access_levels.clone(),
access_levels,
crate_version: krate.version.take(),
orphan_impl_items: Vec::new(),
orphan_trait_impls: Vec::new(),
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/passes/strip_private.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub const STRIP_PRIVATE: Pass =
pub fn strip_private(mut krate: clean::Crate, cx: &DocContext) -> clean::Crate {
// This stripper collects all *retained* nodes.
let mut retained = DefIdSet();
let access_levels = cx.access_levels.borrow().clone();
let access_levels = cx.renderinfo.borrow().access_levels.clone();

// strip all private items
{
Expand Down
7 changes: 5 additions & 2 deletions src/librustdoc/visit_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,10 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
Def::Enum(did) |
Def::ForeignTy(did) |
Def::TyAlias(did) if !self_is_hidden => {
self.cx.access_levels.borrow_mut().map.insert(did, AccessLevel::Public);
self.cx.renderinfo
.borrow_mut()
.access_levels.map
.insert(did, AccessLevel::Public);
},
Def::Mod(did) => if !self_is_hidden {
::visit_lib::LibEmbargoVisitor::new(self.cx).visit_mod(did);
Expand All @@ -284,7 +287,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> RustdocVisitor<'a, 'tcx, 'rcx, 'cstore> {
Some(n) => n, None => return false
};

let is_private = !self.cx.access_levels.borrow().is_public(def_did);
let is_private = !self.cx.renderinfo.borrow().access_levels.is_public(def_did);
let is_hidden = inherits_doc_hidden(self.cx, def_node_id);

// Only inline if requested or if the item would otherwise be stripped
Expand Down
2 changes: 1 addition & 1 deletion src/librustdoc/visit_lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl<'a, 'tcx, 'rcx, 'cstore> LibEmbargoVisitor<'a, 'tcx, 'rcx, 'cstore> {
) -> LibEmbargoVisitor<'a, 'tcx, 'rcx, 'cstore> {
LibEmbargoVisitor {
cx,
access_levels: cx.access_levels.borrow_mut(),
access_levels: RefMut::map(cx.renderinfo.borrow_mut(), |ri| &mut ri.access_levels),
prev_level: Some(AccessLevel::Public),
visited_mods: FxHashSet()
}
Expand Down

0 comments on commit c754e82

Please sign in to comment.