Skip to content

Commit d9c87c7

Browse files
committed
librustc: De-@mut the moves map
1 parent f7393d8 commit d9c87c7

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/librustc/middle/borrowck/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,8 @@ impl BorrowckCtxt {
475475
}
476476

477477
pub fn is_move(&self, id: ast::NodeId) -> bool {
478-
self.moves_map.contains(&id)
478+
let moves_map = self.moves_map.borrow();
479+
moves_map.get().contains(&id)
479480
}
480481

481482
pub fn cat_expr(&self, expr: @ast::Expr) -> mc::cmt {

src/librustc/middle/check_match.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -889,7 +889,8 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
889889
by_ref_span = Some(span);
890890
}
891891
BindByValue(_) => {
892-
if cx.moves_map.contains(&id) {
892+
let moves_map = cx.moves_map.borrow();
893+
if moves_map.get().contains(&id) {
893894
any_by_move = true;
894895
}
895896
}
@@ -926,7 +927,8 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt,
926927
if pat_is_binding(def_map, p) {
927928
match p.node {
928929
PatIdent(_, _, sub) => {
929-
if cx.moves_map.contains(&p.id) {
930+
let moves_map = cx.moves_map.borrow();
931+
if moves_map.get().contains(&p.id) {
930932
check_move(p, sub);
931933
}
932934
}

src/librustc/middle/moves.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ pub struct CaptureVar {
161161

162162
pub type CaptureMap = @RefCell<HashMap<NodeId, @[CaptureVar]>>;
163163

164-
pub type MovesMap = @mut HashSet<NodeId>;
164+
pub type MovesMap = @RefCell<HashSet<NodeId>>;
165165

166166
/**
167167
* Set of variable node-ids that are moved.
@@ -215,7 +215,7 @@ pub fn compute_moves(tcx: ty::ctxt,
215215
tcx: tcx,
216216
method_map: method_map,
217217
move_maps: MoveMaps {
218-
moves_map: @mut HashSet::new(),
218+
moves_map: @RefCell::new(HashSet::new()),
219219
capture_map: @RefCell::new(HashMap::new()),
220220
moved_variables_set: @mut HashSet::new()
221221
}
@@ -283,7 +283,10 @@ impl VisitContext {
283283

284284
let expr_ty = ty::expr_ty_adjusted(self.tcx, expr);
285285
if ty::type_moves_by_default(self.tcx, expr_ty) {
286-
self.move_maps.moves_map.insert(expr.id);
286+
{
287+
let mut moves_map = self.move_maps.moves_map.borrow_mut();
288+
moves_map.get().insert(expr.id);
289+
}
287290
self.use_expr(expr, Move);
288291
} else {
289292
self.use_expr(expr, Read);
@@ -388,7 +391,12 @@ impl VisitContext {
388391
// closures should be noncopyable, they shouldn't move by default;
389392
// calling a closure should only consume it if it's once.
390393
if mode == Move {
391-
self.move_maps.moves_map.insert(callee.id);
394+
{
395+
let mut moves_map = self.move_maps
396+
.moves_map
397+
.borrow_mut();
398+
moves_map.get().insert(callee.id);
399+
}
392400
}
393401
self.use_expr(callee, mode);
394402
self.use_fn_args(callee.id, *args);
@@ -643,7 +651,10 @@ impl VisitContext {
643651
id, bm, binding_moves);
644652

645653
if binding_moves {
646-
self.move_maps.moves_map.insert(id);
654+
{
655+
let mut moves_map = self.move_maps.moves_map.borrow_mut();
656+
moves_map.get().insert(id);
657+
}
647658
}
648659
})
649660
}

0 commit comments

Comments
 (0)