Skip to content

Commit 7eed184

Browse files
committed
visit::Visitor refactor: replace (&mut BorrowckVisitor, @BorrowckCtxt) with &mut BorrowckCtxt.
1 parent eb55348 commit 7eed184

File tree

6 files changed

+33
-36
lines changed

6 files changed

+33
-36
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ use util::ppaux::Repr;
3333

3434
#[deriving(Clone)]
3535
struct CheckLoanCtxt<'self> {
36-
bccx: @BorrowckCtxt,
36+
bccx: &'self BorrowckCtxt,
3737
dfcx_loans: &'self LoanDataFlow,
3838
move_data: @move_data::FlowedMoveData,
3939
all_loans: &'self [Loan],
@@ -60,7 +60,7 @@ impl<'self> Visitor<()> for CheckLoanCtxt<'self> {
6060
}
6161
}
6262

63-
pub fn check_loans(bccx: @BorrowckCtxt,
63+
pub fn check_loans(bccx: &BorrowckCtxt,
6464
dfcx_loans: &LoanDataFlow,
6565
move_data: move_data::FlowedMoveData,
6666
all_loans: &[Loan],

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use syntax::ast_util;
2222
use syntax::codemap::Span;
2323
use util::ppaux::{UserString};
2424

25-
pub fn gather_decl(bccx: @BorrowckCtxt,
25+
pub fn gather_decl(bccx: &BorrowckCtxt,
2626
move_data: &mut MoveData,
2727
decl_id: ast::NodeId,
2828
_decl_span: Span,
@@ -31,23 +31,23 @@ pub fn gather_decl(bccx: @BorrowckCtxt,
3131
move_data.add_move(bccx.tcx, loan_path, decl_id, Declared);
3232
}
3333

34-
pub fn gather_move_from_expr(bccx: @BorrowckCtxt,
34+
pub fn gather_move_from_expr(bccx: &BorrowckCtxt,
3535
move_data: &mut MoveData,
3636
move_expr: @ast::Expr,
3737
cmt: mc::cmt) {
3838
gather_move_from_expr_or_pat(bccx, move_data, move_expr.id,
3939
MoveExpr(move_expr), cmt);
4040
}
4141

42-
pub fn gather_move_from_pat(bccx: @BorrowckCtxt,
42+
pub fn gather_move_from_pat(bccx: &BorrowckCtxt,
4343
move_data: &mut MoveData,
4444
move_pat: @ast::Pat,
4545
cmt: mc::cmt) {
4646
gather_move_from_expr_or_pat(bccx, move_data, move_pat.id,
4747
MovePat(move_pat), cmt);
4848
}
4949

50-
fn gather_move_from_expr_or_pat(bccx: @BorrowckCtxt,
50+
fn gather_move_from_expr_or_pat(bccx: &BorrowckCtxt,
5151
move_data: &mut MoveData,
5252
move_id: ast::NodeId,
5353
move_kind: MoveKind,
@@ -66,7 +66,7 @@ fn gather_move_from_expr_or_pat(bccx: @BorrowckCtxt,
6666
}
6767
}
6868

69-
pub fn gather_captures(bccx: @BorrowckCtxt,
69+
pub fn gather_captures(bccx: &BorrowckCtxt,
7070
move_data: &mut MoveData,
7171
closure_expr: @ast::Expr) {
7272
let captured_vars = bccx.capture_map.get(&closure_expr.id);
@@ -83,7 +83,7 @@ pub fn gather_captures(bccx: @BorrowckCtxt,
8383
}
8484
}
8585

86-
pub fn gather_assignment(bccx: @BorrowckCtxt,
86+
pub fn gather_assignment(bccx: &BorrowckCtxt,
8787
move_data: &mut MoveData,
8888
assignment_id: ast::NodeId,
8989
assignment_span: Span,
@@ -96,7 +96,7 @@ pub fn gather_assignment(bccx: @BorrowckCtxt,
9696
assignee_id);
9797
}
9898

99-
fn check_is_legal_to_move_from(bccx: @BorrowckCtxt,
99+
fn check_is_legal_to_move_from(bccx: &BorrowckCtxt,
100100
cmt0: mc::cmt,
101101
cmt: mc::cmt) -> bool {
102102
match cmt.cat {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use syntax::ast;
2020
use syntax::codemap::Span;
2121
use util::ppaux::{note_and_explain_region};
2222

23-
pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
23+
pub fn guarantee_lifetime(bccx: &BorrowckCtxt,
2424
item_scope_id: ast::NodeId,
2525
root_scope_id: ast::NodeId,
2626
span: Span,
@@ -42,8 +42,8 @@ pub fn guarantee_lifetime(bccx: @BorrowckCtxt,
4242
///////////////////////////////////////////////////////////////////////////
4343
// Private
4444

45-
struct GuaranteeLifetimeContext {
46-
bccx: @BorrowckCtxt,
45+
struct GuaranteeLifetimeContext<'self> {
46+
bccx: &'self BorrowckCtxt,
4747

4848
// the node id of the function body for the enclosing item
4949
item_scope_id: ast::NodeId,
@@ -58,7 +58,7 @@ struct GuaranteeLifetimeContext {
5858
cmt_original: mc::cmt
5959
}
6060

61-
impl GuaranteeLifetimeContext {
61+
impl<'self> GuaranteeLifetimeContext<'self> {
6262
fn tcx(&self) -> ty::ctxt {
6363
self.bccx.tcx
6464
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ mod gather_moves;
6464
/// No good. Instead what will happen is that `root_ub` will be set to the
6565
/// body of the while loop and we will refuse to root the pointer `&*x`
6666
/// because it would have to be rooted for a region greater than `root_ub`.
67-
struct GatherLoanCtxt {
68-
bccx: @BorrowckCtxt,
67+
struct GatherLoanCtxt<'self> {
68+
bccx: &'self BorrowckCtxt,
6969
id_range: id_range,
7070
move_data: @mut move_data::MoveData,
7171
all_loans: @mut ~[Loan],
7272
item_ub: ast::NodeId,
7373
repeating_ids: ~[ast::NodeId]
7474
}
7575

76-
impl visit::Visitor<()> for GatherLoanCtxt {
76+
impl<'self> visit::Visitor<()> for GatherLoanCtxt<'self> {
7777
fn visit_expr(&mut self, ex:@Expr, _:()) {
7878
gather_loans_in_expr(self, ex);
7979
}
@@ -100,7 +100,7 @@ impl visit::Visitor<()> for GatherLoanCtxt {
100100
fn visit_item(&mut self, _:@ast::item, _:()) { }
101101
}
102102

103-
pub fn gather_loans(bccx: @BorrowckCtxt,
103+
pub fn gather_loans(bccx: &BorrowckCtxt,
104104
decl: &ast::fn_decl,
105105
body: &ast::Block)
106106
-> (id_range, @mut ~[Loan], @mut move_data::MoveData) {
@@ -315,7 +315,7 @@ fn gather_loans_in_expr(this: &mut GatherLoanCtxt,
315315
}
316316
}
317317

318-
impl GatherLoanCtxt {
318+
impl<'self> GatherLoanCtxt<'self> {
319319
pub fn tcx(&self) -> ty::ctxt { self.bccx.tcx }
320320

321321
pub fn push_repeating_id(&mut self, id: ast::NodeId) {
@@ -532,7 +532,7 @@ impl GatherLoanCtxt {
532532
// }
533533
// }
534534

535-
fn check_mutability(bccx: @BorrowckCtxt,
535+
fn check_mutability(bccx: &BorrowckCtxt,
536536
borrow_span: Span,
537537
cmt: mc::cmt,
538538
req_mutbl: LoanMutability) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum RestrictionResult {
2323
SafeIf(@LoanPath, ~[Restriction])
2424
}
2525

26-
pub fn compute_restrictions(bccx: @BorrowckCtxt,
26+
pub fn compute_restrictions(bccx: &BorrowckCtxt,
2727
span: Span,
2828
cmt: mc::cmt,
2929
restr: RestrictionSet) -> RestrictionResult {
@@ -39,13 +39,13 @@ pub fn compute_restrictions(bccx: @BorrowckCtxt,
3939
///////////////////////////////////////////////////////////////////////////
4040
// Private
4141

42-
struct RestrictionsContext {
43-
bccx: @BorrowckCtxt,
42+
struct RestrictionsContext<'self> {
43+
bccx: &'self BorrowckCtxt,
4444
span: Span,
4545
cmt_original: mc::cmt
4646
}
4747

48-
impl RestrictionsContext {
48+
impl<'self> RestrictionsContext<'self> {
4949
fn tcx(&self) -> ty::ctxt {
5050
self.bccx.tcx
5151
}

src/librustc/middle/borrowck/mod.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,10 @@ impl Clone for LoanDataFlowOperator {
6161

6262
pub type LoanDataFlow = DataFlowContext<LoanDataFlowOperator>;
6363

64-
struct BorrowckVisitor;
65-
66-
impl Visitor<@BorrowckCtxt> for BorrowckVisitor {
64+
impl Visitor<()> for BorrowckCtxt {
6765
fn visit_fn(&mut self, fk:&fn_kind, fd:&fn_decl,
68-
b:&Block, s:Span, n:NodeId, e:@BorrowckCtxt) {
69-
borrowck_fn(self, fk, fd, b, s, n, e);
66+
b:&Block, s:Span, n:NodeId, _:()) {
67+
borrowck_fn(self, fk, fd, b, s, n);
7068
}
7169
}
7270

@@ -78,7 +76,7 @@ pub fn check_crate(
7876
capture_map: moves::CaptureMap,
7977
crate: &ast::Crate) -> (root_map, write_guard_map)
8078
{
81-
let bccx = @BorrowckCtxt {
79+
let mut bccx = BorrowckCtxt {
8280
tcx: tcx,
8381
method_map: method_map,
8482
moves_map: moves_map,
@@ -96,9 +94,9 @@ pub fn check_crate(
9694
guaranteed_paths: 0,
9795
}
9896
};
97+
let bccx = &mut bccx;
9998

100-
let mut v = BorrowckVisitor;
101-
visit::walk_crate(&mut v, crate, bccx);
99+
visit::walk_crate(bccx, crate, ());
102100

103101
if tcx.sess.borrowck_stats() {
104102
io::println("--- borrowck stats ---");
@@ -116,20 +114,19 @@ pub fn check_crate(
116114

117115
return (bccx.root_map, bccx.write_guard_map);
118116

119-
fn make_stat(bccx: &BorrowckCtxt, stat: uint) -> ~str {
117+
fn make_stat(bccx: &mut BorrowckCtxt, stat: uint) -> ~str {
120118
let stat_f = stat as float;
121119
let total = bccx.stats.guaranteed_paths as float;
122120
fmt!("%u (%.0f%%)", stat , stat_f * 100f / total)
123121
}
124122
}
125123

126-
fn borrowck_fn(v: &mut BorrowckVisitor,
124+
fn borrowck_fn(this: &mut BorrowckCtxt,
127125
fk: &visit::fn_kind,
128126
decl: &ast::fn_decl,
129127
body: &ast::Block,
130128
sp: Span,
131-
id: ast::NodeId,
132-
this: @BorrowckCtxt) {
129+
id: ast::NodeId) {
133130
match fk {
134131
&visit::fk_anon(*) |
135132
&visit::fk_fn_block(*) => {
@@ -166,7 +163,7 @@ fn borrowck_fn(v: &mut BorrowckVisitor,
166163
}
167164
}
168165

169-
visit::walk_fn(v, fk, decl, body, sp, id, this);
166+
visit::walk_fn(this, fk, decl, body, sp, id, ());
170167
}
171168

172169
// ----------------------------------------------------------------------

0 commit comments

Comments
 (0)