Skip to content

Commit 57d57c6

Browse files
Mutate DocContext from LibEmbargoVisitor and RustdocVisitor
We have &mut access, so remove the RefCell borrowing
1 parent e2b6f4c commit 57d57c6

File tree

3 files changed

+23
-27
lines changed

3 files changed

+23
-27
lines changed

src/librustdoc/clean/mod.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -136,24 +136,22 @@ pub struct Crate {
136136
pub collapsed: bool,
137137
}
138138

139-
pub fn krate(cx: &mut DocContext<'a>) -> Crate {
139+
pub fn krate(mut cx: &mut DocContext<'_>) -> Crate {
140140
use crate::visit_lib::LibEmbargoVisitor;
141141

142-
let v = crate::visit_ast::RustdocVisitor::new(&cx);
143-
let module = v.visit(cx.tcx.hir().krate());
142+
let krate = cx.tcx.hir().krate();
143+
let module = crate::visit_ast::RustdocVisitor::new(&mut cx).visit(krate);
144144

145-
{
146-
let mut r = cx.renderinfo.borrow_mut();
147-
r.deref_trait_did = cx.tcx.lang_items().deref_trait();
148-
r.deref_mut_trait_did = cx.tcx.lang_items().deref_mut_trait();
149-
r.owned_box_did = cx.tcx.lang_items().owned_box();
150-
}
145+
let mut r = cx.renderinfo.get_mut();
146+
r.deref_trait_did = cx.tcx.lang_items().deref_trait();
147+
r.deref_mut_trait_did = cx.tcx.lang_items().deref_mut_trait();
148+
r.owned_box_did = cx.tcx.lang_items().owned_box();
151149

152150
let mut externs = Vec::new();
153151
for &cnum in cx.tcx.crates().iter() {
154152
externs.push((cnum, cnum.clean(cx)));
155153
// Analyze doc-reachability for extern items
156-
LibEmbargoVisitor::new(cx).visit_lib(cnum);
154+
LibEmbargoVisitor::new(&mut cx).visit_lib(cnum);
157155
}
158156
externs.sort_by(|&(a, _), &(b, _)| a.cmp(&b));
159157

src/librustdoc/visit_ast.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ fn def_id_to_path(
4141
// framework from syntax?.
4242

4343
pub struct RustdocVisitor<'a, 'tcx> {
44-
cx: &'a core::DocContext<'tcx>,
44+
cx: &'a mut core::DocContext<'tcx>,
4545
view_item_stack: FxHashSet<hir::HirId>,
4646
inlining: bool,
4747
/// Are the current module and all of its parents public?
@@ -51,7 +51,7 @@ pub struct RustdocVisitor<'a, 'tcx> {
5151

5252
impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
5353
pub fn new(
54-
cx: &'a core::DocContext<'tcx>
54+
cx: &'a mut core::DocContext<'tcx>
5555
) -> RustdocVisitor<'a, 'tcx> {
5656
// If the root is re-exported, terminate all recursion.
5757
let mut stack = FxHashSet::default();
@@ -84,7 +84,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
8484
);
8585
module.is_crate = true;
8686

87-
self.cx.renderinfo.borrow_mut().exact_paths = self.exact_paths;
87+
self.cx.renderinfo.get_mut().exact_paths = self.exact_paths;
8888

8989
module
9090
}
@@ -292,7 +292,7 @@ impl<'a, 'tcx> RustdocVisitor<'a, 'tcx> {
292292
Res::Def(DefKind::ForeignTy, did) |
293293
Res::Def(DefKind::TyAlias, did) if !self_is_hidden => {
294294
self.cx.renderinfo
295-
.borrow_mut()
295+
.get_mut()
296296
.access_levels.map
297297
.insert(did, AccessLevel::Public);
298298
},

src/librustdoc/visit_lib.rs

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,20 @@
11
use rustc::middle::privacy::{AccessLevels, AccessLevel};
22
use rustc::hir::def::{Res, DefKind};
33
use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefId};
4-
use rustc::ty::Visibility;
4+
use rustc::ty::{TyCtxt, Visibility};
55
use rustc::util::nodemap::FxHashSet;
66
use syntax::symbol::sym;
77

8-
use std::cell::RefMut;
9-
108
use crate::clean::{AttributesExt, NestedAttributesExt};
119

1210
// FIXME: this may not be exhaustive, but is sufficient for rustdocs current uses
1311

1412
/// Similar to `librustc_privacy::EmbargoVisitor`, but also takes
1513
/// specific rustdoc annotations into account (i.e., `doc(hidden)`)
1614
pub struct LibEmbargoVisitor<'a, 'tcx> {
17-
cx: &'a crate::core::DocContext<'tcx>,
15+
tcx: TyCtxt<'tcx>,
1816
// Accessibility levels for reachable nodes
19-
access_levels: RefMut<'a, AccessLevels<DefId>>,
17+
access_levels: &'a mut AccessLevels<DefId>,
2018
// Previous accessibility level, None means unreachable
2119
prev_level: Option<AccessLevel>,
2220
// Keeps track of already visited modules, in case a module re-exports its parent
@@ -25,13 +23,13 @@ pub struct LibEmbargoVisitor<'a, 'tcx> {
2523

2624
impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
2725
pub fn new(
28-
cx: &'a crate::core::DocContext<'tcx>
26+
cx: &'a mut crate::core::DocContext<'tcx>
2927
) -> LibEmbargoVisitor<'a, 'tcx> {
3028
LibEmbargoVisitor {
31-
cx,
32-
access_levels: RefMut::map(cx.renderinfo.borrow_mut(), |ri| &mut ri.access_levels),
29+
tcx: cx.tcx,
30+
access_levels: &mut cx.renderinfo.get_mut().access_levels,
3331
prev_level: Some(AccessLevel::Public),
34-
visited_mods: FxHashSet::default()
32+
visited_mods: FxHashSet::default(),
3533
}
3634
}
3735

@@ -43,7 +41,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
4341

4442
// Updates node level and returns the updated level
4543
fn update(&mut self, did: DefId, level: Option<AccessLevel>) -> Option<AccessLevel> {
46-
let is_hidden = self.cx.tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden);
44+
let is_hidden = self.tcx.get_attrs(did).lists(sym::doc).has_word(sym::hidden);
4745

4846
let old_level = self.access_levels.map.get(&did).cloned();
4947
// Accessibility levels can only grow
@@ -60,9 +58,9 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
6058
return;
6159
}
6260

63-
for item in self.cx.tcx.item_children(def_id).iter() {
61+
for item in self.tcx.item_children(def_id).iter() {
6462
if let Some(def_id) = item.res.opt_def_id() {
65-
if self.cx.tcx.def_key(def_id).parent.map_or(false, |d| d == def_id.index) ||
63+
if self.tcx.def_key(def_id).parent.map_or(false, |d| d == def_id.index) ||
6664
item.vis == Visibility::Public {
6765
self.visit_item(item.res);
6866
}
@@ -72,7 +70,7 @@ impl<'a, 'tcx> LibEmbargoVisitor<'a, 'tcx> {
7270

7371
fn visit_item(&mut self, res: Res) {
7472
let def_id = res.def_id();
75-
let vis = self.cx.tcx.visibility(def_id);
73+
let vis = self.tcx.visibility(def_id);
7674
let inherited_item_level = if vis == Visibility::Public {
7775
self.prev_level
7876
} else {

0 commit comments

Comments
 (0)