提交 fc0b466f 编写于 作者: P Patrick Walton

librustc: De-`@mut` `all_loans` in the borrow checker

上级 0afae85b
......@@ -26,6 +26,7 @@
use util::common::indenter;
use util::ppaux::{Repr};
use std::cell::RefCell;
use syntax::ast;
use syntax::ast_util::id_range;
use syntax::codemap::Span;
......@@ -68,7 +69,7 @@ struct GatherLoanCtxt<'a> {
bccx: &'a BorrowckCtxt,
id_range: id_range,
move_data: @move_data::MoveData,
all_loans: @mut ~[Loan],
all_loans: @RefCell<~[Loan]>,
item_ub: ast::NodeId,
repeating_ids: ~[ast::NodeId]
}
......@@ -103,11 +104,11 @@ fn visit_item(&mut self, _:@ast::item, _:()) { }
pub fn gather_loans(bccx: &BorrowckCtxt,
decl: &ast::fn_decl,
body: ast::P<ast::Block>)
-> (id_range, @mut ~[Loan], @move_data::MoveData) {
-> (id_range, @RefCell<~[Loan]>, @move_data::MoveData) {
let mut glcx = GatherLoanCtxt {
bccx: bccx,
id_range: id_range::max(),
all_loans: @mut ~[],
all_loans: @RefCell::new(~[]),
item_ub: body.id,
repeating_ids: ~[body.id],
move_data: @MoveData::new()
......@@ -511,9 +512,9 @@ pub fn guarantee_valid(&mut self,
self.mark_loan_path_as_mutated(loan_path);
}
let all_loans = &mut *self.all_loans; // FIXME(#5074)
let all_loans = self.all_loans.borrow();
Loan {
index: all_loans.len(),
index: all_loans.get().len(),
loan_path: loan_path,
cmt: cmt,
mutbl: req_mutbl,
......@@ -531,7 +532,10 @@ pub fn guarantee_valid(&mut self,
// let loan_path = loan.loan_path;
// let loan_gen_scope = loan.gen_scope;
// let loan_kill_scope = loan.kill_scope;
self.all_loans.push(loan);
{
let mut all_loans = self.all_loans.borrow_mut();
all_loans.get().push(loan);
}
// if loan_gen_scope != borrow_id {
// FIXME(#6268) Nested method calls
......
......@@ -133,16 +133,18 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
// Check the body of fn items.
let (id_range, all_loans, move_data) =
gather_loans::gather_loans(this, decl, body);
let mut loan_dfcx =
DataFlowContext::new(this.tcx,
this.method_map,
LoanDataFlowOperator,
id_range,
all_loans.len());
for (loan_idx, loan) in all_loans.iter().enumerate() {
let all_loans = all_loans.borrow();
let mut loan_dfcx = DataFlowContext::new(this.tcx,
this.method_map,
LoanDataFlowOperator,
id_range,
all_loans.get().len());
for (loan_idx, loan) in all_loans.get().iter().enumerate() {
loan_dfcx.add_gen(loan.gen_scope, loan_idx);
loan_dfcx.add_kill(loan.kill_scope, loan_idx);
}
loan_dfcx.propagate(body);
let flowed_moves = move_data::FlowedMoveData::new(move_data,
......@@ -152,7 +154,7 @@ fn borrowck_fn(this: &mut BorrowckCtxt,
body);
check_loans::check_loans(this, &loan_dfcx, flowed_moves,
*all_loans, body);
*all_loans.get(), body);
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册