Skip to content

Commit fc0b466

Browse files
committed
librustc: De-@mut all_loans in the borrow checker
1 parent 0afae85 commit fc0b466

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

src/librustc/middle/borrowck/gather_loans/mod.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use middle::ty;
2626
use util::common::indenter;
2727
use util::ppaux::{Repr};
2828

29+
use std::cell::RefCell;
2930
use syntax::ast;
3031
use syntax::ast_util::id_range;
3132
use syntax::codemap::Span;
@@ -68,7 +69,7 @@ struct GatherLoanCtxt<'a> {
6869
bccx: &'a BorrowckCtxt,
6970
id_range: id_range,
7071
move_data: @move_data::MoveData,
71-
all_loans: @mut ~[Loan],
72+
all_loans: @RefCell<~[Loan]>,
7273
item_ub: ast::NodeId,
7374
repeating_ids: ~[ast::NodeId]
7475
}
@@ -103,11 +104,11 @@ impl<'a> visit::Visitor<()> for GatherLoanCtxt<'a> {
103104
pub fn gather_loans(bccx: &BorrowckCtxt,
104105
decl: &ast::fn_decl,
105106
body: ast::P<ast::Block>)
106-
-> (id_range, @mut ~[Loan], @move_data::MoveData) {
107+
-> (id_range, @RefCell<~[Loan]>, @move_data::MoveData) {
107108
let mut glcx = GatherLoanCtxt {
108109
bccx: bccx,
109110
id_range: id_range::max(),
110-
all_loans: @mut ~[],
111+
all_loans: @RefCell::new(~[]),
111112
item_ub: body.id,
112113
repeating_ids: ~[body.id],
113114
move_data: @MoveData::new()
@@ -511,9 +512,9 @@ impl<'a> GatherLoanCtxt<'a> {
511512
self.mark_loan_path_as_mutated(loan_path);
512513
}
513514

514-
let all_loans = &mut *self.all_loans; // FIXME(#5074)
515+
let all_loans = self.all_loans.borrow();
515516
Loan {
516-
index: all_loans.len(),
517+
index: all_loans.get().len(),
517518
loan_path: loan_path,
518519
cmt: cmt,
519520
mutbl: req_mutbl,
@@ -531,7 +532,10 @@ impl<'a> GatherLoanCtxt<'a> {
531532
// let loan_path = loan.loan_path;
532533
// let loan_gen_scope = loan.gen_scope;
533534
// let loan_kill_scope = loan.kill_scope;
534-
self.all_loans.push(loan);
535+
{
536+
let mut all_loans = self.all_loans.borrow_mut();
537+
all_loans.get().push(loan);
538+
}
535539

536540
// if loan_gen_scope != borrow_id {
537541
// FIXME(#6268) Nested method calls

src/librustc/middle/borrowck/mod.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,18 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
133133
// Check the body of fn items.
134134
let (id_range, all_loans, move_data) =
135135
gather_loans::gather_loans(this, decl, body);
136-
let mut loan_dfcx =
137-
DataFlowContext::new(this.tcx,
138-
this.method_map,
139-
LoanDataFlowOperator,
140-
id_range,
141-
all_loans.len());
142-
for (loan_idx, loan) in all_loans.iter().enumerate() {
136+
137+
let all_loans = all_loans.borrow();
138+
let mut loan_dfcx = DataFlowContext::new(this.tcx,
139+
this.method_map,
140+
LoanDataFlowOperator,
141+
id_range,
142+
all_loans.get().len());
143+
for (loan_idx, loan) in all_loans.get().iter().enumerate() {
143144
loan_dfcx.add_gen(loan.gen_scope, loan_idx);
144145
loan_dfcx.add_kill(loan.kill_scope, loan_idx);
145146
}
147+
146148
loan_dfcx.propagate(body);
147149

148150
let flowed_moves = move_data::FlowedMoveData::new(move_data,
@@ -152,7 +154,7 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
152154
body);
153155

154156
check_loans::check_loans(this, &loan_dfcx, flowed_moves,
155-
*all_loans, body);
157+
*all_loans.get(), body);
156158
}
157159
}
158160

0 commit comments

Comments
 (0)