Skip to content

Commit d947fce

Browse files
committed
---
yaml --- r: 151002 b: refs/heads/try2 c: d55deae h: refs/heads/master v: v3
1 parent 6e8bea7 commit d947fce

File tree

7 files changed

+138
-161
lines changed

7 files changed

+138
-161
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 3683f16e9e88947ac58d5dd95fa2254a05d5bc88
8+
refs/heads/try2: d55deaeb217aeec7c1a5af859d389d926b08f80a
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/borrowck/check_loans.rs

Lines changed: 52 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ use syntax::visit::Visitor;
3030
use syntax::visit;
3131
use util::ppaux::Repr;
3232

33+
use std::rc::Rc;
34+
3335
struct CheckLoanCtxt<'a> {
3436
bccx: &'a BorrowckCtxt<'a>,
3537
dfcx_loans: &'a LoanDataFlow<'a>,
@@ -82,7 +84,7 @@ pub fn check_loans(bccx: &BorrowckCtxt,
8284
#[deriving(Eq)]
8385
enum MoveError {
8486
MoveOk,
85-
MoveWhileBorrowed(/*loan*/@LoanPath, /*loan*/Span)
87+
MoveWhileBorrowed(/*loan*/Rc<LoanPath>, /*loan*/Span)
8688
}
8789

8890
impl<'a> CheckLoanCtxt<'a> {
@@ -121,7 +123,7 @@ impl<'a> CheckLoanCtxt<'a> {
121123

122124
pub fn each_in_scope_restriction(&self,
123125
scope_id: ast::NodeId,
124-
loan_path: @LoanPath,
126+
loan_path: &LoanPath,
125127
op: |&Loan, &Restriction| -> bool)
126128
-> bool {
127129
//! Iterates through all the in-scope restrictions for the
@@ -133,7 +135,7 @@ impl<'a> CheckLoanCtxt<'a> {
133135

134136
let mut ret = true;
135137
for restr in loan.restrictions.iter() {
136-
if restr.loan_path == loan_path {
138+
if *restr.loan_path == *loan_path {
137139
if !op(loan, restr) {
138140
ret = false;
139141
break;
@@ -243,7 +245,7 @@ impl<'a> CheckLoanCtxt<'a> {
243245
"it".to_owned()
244246
} else {
245247
format!("`{}`",
246-
self.bccx.loan_path_to_str(old_loan.loan_path))
248+
self.bccx.loan_path_to_str(&*old_loan.loan_path))
247249
};
248250

249251
match (new_loan.kind, old_loan.kind) {
@@ -252,15 +254,15 @@ impl<'a> CheckLoanCtxt<'a> {
252254
new_loan.span,
253255
format!("cannot borrow `{}` as mutable \
254256
more than once at a time",
255-
self.bccx.loan_path_to_str(new_loan.loan_path)));
257+
self.bccx.loan_path_to_str(&*new_loan.loan_path)));
256258
}
257259

258260
(ty::UniqueImmBorrow, _) => {
259261
self.bccx.span_err(
260262
new_loan.span,
261263
format!("closure requires unique access to `{}` \
262264
but {} is already borrowed",
263-
self.bccx.loan_path_to_str(new_loan.loan_path),
265+
self.bccx.loan_path_to_str(&*new_loan.loan_path),
264266
old_pronoun));
265267
}
266268

@@ -269,7 +271,7 @@ impl<'a> CheckLoanCtxt<'a> {
269271
new_loan.span,
270272
format!("cannot borrow `{}` as {} because \
271273
previous closure requires unique access",
272-
self.bccx.loan_path_to_str(new_loan.loan_path),
274+
self.bccx.loan_path_to_str(&*new_loan.loan_path),
273275
new_loan.kind.to_user_str()));
274276
}
275277

@@ -278,7 +280,7 @@ impl<'a> CheckLoanCtxt<'a> {
278280
new_loan.span,
279281
format!("cannot borrow `{}` as {} because \
280282
{} is also borrowed as {}",
281-
self.bccx.loan_path_to_str(new_loan.loan_path),
283+
self.bccx.loan_path_to_str(&*new_loan.loan_path),
282284
new_loan.kind.to_user_str(),
283285
old_pronoun,
284286
old_loan.kind.to_user_str()));
@@ -290,7 +292,7 @@ impl<'a> CheckLoanCtxt<'a> {
290292
self.bccx.span_note(
291293
span,
292294
format!("borrow occurs due to use of `{}` in closure",
293-
self.bccx.loan_path_to_str(new_loan.loan_path)));
295+
self.bccx.loan_path_to_str(&*new_loan.loan_path)));
294296
}
295297
_ => { }
296298
}
@@ -300,34 +302,34 @@ impl<'a> CheckLoanCtxt<'a> {
300302
format!("the mutable borrow prevents subsequent \
301303
moves, borrows, or modification of `{0}` \
302304
until the borrow ends",
303-
self.bccx.loan_path_to_str(old_loan.loan_path))
305+
self.bccx.loan_path_to_str(&*old_loan.loan_path))
304306
}
305307

306308
ty::ImmBorrow => {
307309
format!("the immutable borrow prevents subsequent \
308310
moves or mutable borrows of `{0}` \
309311
until the borrow ends",
310-
self.bccx.loan_path_to_str(old_loan.loan_path))
312+
self.bccx.loan_path_to_str(&*old_loan.loan_path))
311313
}
312314

313315
ty::UniqueImmBorrow => {
314316
format!("the unique capture prevents subsequent \
315317
moves or borrows of `{0}` \
316318
until the borrow ends",
317-
self.bccx.loan_path_to_str(old_loan.loan_path))
319+
self.bccx.loan_path_to_str(&*old_loan.loan_path))
318320
}
319321
};
320322

321323
let borrow_summary = match old_loan.cause {
322324
ClosureCapture(_) => {
323325
format!("previous borrow of `{}` occurs here due to \
324326
use in closure",
325-
self.bccx.loan_path_to_str(old_loan.loan_path))
327+
self.bccx.loan_path_to_str(&*old_loan.loan_path))
326328
}
327329

328330
AddrOf | AutoRef | RefBinding => {
329331
format!("previous borrow of `{}` occurs here",
330-
self.bccx.loan_path_to_str(old_loan.loan_path))
332+
self.bccx.loan_path_to_str(&*old_loan.loan_path))
331333
}
332334
};
333335

@@ -356,7 +358,7 @@ impl<'a> CheckLoanCtxt<'a> {
356358
id: ast::NodeId,
357359
span: Span,
358360
use_kind: MovedValueUseKind,
359-
lp: @LoanPath) {
361+
lp: &Rc<LoanPath>) {
360362
/*!
361363
* Reports an error if `expr` (which should be a path)
362364
* is using a moved/uninitialized value
@@ -368,7 +370,7 @@ impl<'a> CheckLoanCtxt<'a> {
368370
self.bccx.report_use_of_moved_value(
369371
span,
370372
use_kind,
371-
lp,
373+
&**lp,
372374
move,
373375
moved_lp);
374376
false
@@ -404,10 +406,10 @@ impl<'a> CheckLoanCtxt<'a> {
404406
if self.is_local_variable(cmt) {
405407
assert!(cmt.mutbl.is_immutable()); // no "const" locals
406408
let lp = opt_loan_path(cmt).unwrap();
407-
self.move_data.each_assignment_of(expr.id, lp, |assign| {
409+
self.move_data.each_assignment_of(expr.id, &lp, |assign| {
408410
self.bccx.report_reassigned_immutable_variable(
409411
expr.span,
410-
lp,
412+
&*lp,
411413
assign);
412414
false
413415
});
@@ -422,7 +424,7 @@ impl<'a> CheckLoanCtxt<'a> {
422424
format!("cannot assign to {} {} `{}`",
423425
cmt.mutbl.to_user_str(),
424426
self.bccx.cmt_to_str(cmt),
425-
self.bccx.loan_path_to_str(lp)));
427+
self.bccx.loan_path_to_str(&*lp)));
426428
}
427429
None => {
428430
self.bccx.span_err(
@@ -571,10 +573,10 @@ impl<'a> CheckLoanCtxt<'a> {
571573
// owned pointer are borrowed, and hence while `v[*]` is not
572574
// restricted from being written, `v` is.
573575
let cont = this.each_in_scope_restriction(expr.id,
574-
loan_path,
576+
&*loan_path,
575577
|loan, restr| {
576578
if restr.set.intersects(RESTR_MUTATE) {
577-
this.report_illegal_mutation(expr, loan_path, loan);
579+
this.report_illegal_mutation(expr, &*loan_path, loan);
578580
false
579581
} else {
580582
true
@@ -623,17 +625,17 @@ impl<'a> CheckLoanCtxt<'a> {
623625
//
624626
// Here the restriction that `v` not be mutated would be misapplied
625627
// to block the subpath `v[1]`.
626-
let full_loan_path = loan_path;
628+
let full_loan_path = loan_path.clone();
627629
let mut loan_path = loan_path;
628630
loop {
629-
match *loan_path {
631+
loan_path = match *loan_path {
630632
// Peel back one layer if, for `loan_path` to be
631633
// mutable, `lp_base` must be mutable. This occurs
632634
// with inherited mutability and with `&mut`
633635
// pointers.
634-
LpExtend(lp_base, mc::McInherited, _) |
635-
LpExtend(lp_base, _, LpDeref(mc::BorrowedPtr(ty::MutBorrow, _))) => {
636-
loan_path = lp_base;
636+
LpExtend(ref lp_base, mc::McInherited, _) |
637+
LpExtend(ref lp_base, _, LpDeref(mc::BorrowedPtr(ty::MutBorrow, _))) => {
638+
lp_base.clone()
637639
}
638640

639641
// Otherwise stop iterating
@@ -642,12 +644,12 @@ impl<'a> CheckLoanCtxt<'a> {
642644
LpVar(_) => {
643645
return true;
644646
}
645-
}
647+
};
646648

647649
// Check for a non-const loan of `loan_path`
648650
let cont = this.each_in_scope_loan(expr.id, |loan| {
649651
if loan.loan_path == loan_path {
650-
this.report_illegal_mutation(expr, full_loan_path, loan);
652+
this.report_illegal_mutation(expr, &*full_loan_path, loan);
651653
false
652654
} else {
653655
true
@@ -700,7 +702,7 @@ impl<'a> CheckLoanCtxt<'a> {
700702
self.bccx.span_note(
701703
loan_span,
702704
format!("borrow of `{}` occurs here",
703-
self.bccx.loan_path_to_str(loan_path)));
705+
self.bccx.loan_path_to_str(&*loan_path)));
704706
}
705707
}
706708
true
@@ -712,13 +714,12 @@ impl<'a> CheckLoanCtxt<'a> {
712714
span: Span) {
713715
for cap_var in self.bccx.capture_map.get(&closure_id).iter() {
714716
let var_id = ast_util::def_id_of_def(cap_var.def).node;
715-
let var_path = @LpVar(var_id);
716717
self.check_if_path_is_moved(closure_id, span,
717-
MovedInCapture, var_path);
718+
MovedInCapture, &Rc::new(LpVar(var_id)));
718719
match cap_var.mode {
719720
moves::CapRef | moves::CapCopy => {}
720721
moves::CapMove => {
721-
check_by_move_capture(self, closure_id, cap_var, var_path);
722+
check_by_move_capture(self, closure_id, cap_var, &LpVar(var_id));
722723
}
723724
}
724725
}
@@ -727,7 +728,7 @@ impl<'a> CheckLoanCtxt<'a> {
727728
fn check_by_move_capture(this: &CheckLoanCtxt,
728729
closure_id: ast::NodeId,
729730
cap_var: &moves::CaptureVar,
730-
move_path: @LoanPath) {
731+
move_path: &LoanPath) {
731732
let move_err = this.analyze_move_out_from(closure_id, move_path);
732733
match move_err {
733734
MoveOk => {}
@@ -740,38 +741,39 @@ impl<'a> CheckLoanCtxt<'a> {
740741
this.bccx.span_note(
741742
loan_span,
742743
format!("borrow of `{}` occurs here",
743-
this.bccx.loan_path_to_str(loan_path)));
744+
this.bccx.loan_path_to_str(&*loan_path)));
744745
}
745746
}
746747
}
747748
}
748749

749750
pub fn analyze_move_out_from(&self,
750751
expr_id: ast::NodeId,
751-
mut move_path: @LoanPath)
752+
move_path: &LoanPath)
752753
-> MoveError {
753754
debug!("analyze_move_out_from(expr_id={:?}, move_path={})",
754755
self.tcx().map.node_to_str(expr_id),
755756
move_path.repr(self.tcx()));
756757

757758
// We must check every element of a move path. See
758759
// `borrowck-move-subcomponent.rs` for a test case.
759-
loop {
760-
// check for a conflicting loan:
761-
let mut ret = MoveOk;
762-
self.each_in_scope_restriction(expr_id, move_path, |loan, _| {
763-
// Any restriction prevents moves.
764-
ret = MoveWhileBorrowed(loan.loan_path, loan.span);
765-
false
766-
});
767760

768-
if ret != MoveOk {
769-
return ret
770-
}
761+
// check for a conflicting loan:
762+
let mut ret = MoveOk;
763+
self.each_in_scope_restriction(expr_id, move_path, |loan, _| {
764+
// Any restriction prevents moves.
765+
ret = MoveWhileBorrowed(loan.loan_path.clone(), loan.span);
766+
false
767+
});
768+
769+
if ret != MoveOk {
770+
return ret
771+
}
771772

772-
match *move_path {
773-
LpVar(_) => return MoveOk,
774-
LpExtend(subpath, _, _) => move_path = subpath,
773+
match *move_path {
774+
LpVar(_) => MoveOk,
775+
LpExtend(ref subpath, _, _) => {
776+
self.analyze_move_out_from(expr_id, &**subpath)
775777
}
776778
}
777779
}
@@ -812,8 +814,7 @@ fn check_loans_in_expr<'a>(this: &mut CheckLoanCtxt<'a>,
812814
if !this.move_data.is_assignee(expr.id) {
813815
let cmt = this.bccx.cat_expr_unadjusted(expr);
814816
debug!("path cmt={}", cmt.repr(this.tcx()));
815-
let r = opt_loan_path(cmt);
816-
for &lp in r.iter() {
817+
for lp in opt_loan_path(cmt).iter() {
817818
this.check_if_path_is_moved(expr.id, expr.span, MovedInUse, lp);
818819
}
819820
}

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@ struct GatherMoveInfo {
3030
span_path_opt: Option<MoveSpanAndPath>
3131
}
3232

33+
use std::rc::Rc;
34+
3335
pub fn gather_decl(bccx: &BorrowckCtxt,
3436
move_data: &MoveData,
3537
decl_id: ast::NodeId,
3638
_decl_span: Span,
3739
var_id: ast::NodeId) {
38-
let loan_path = @LpVar(var_id);
40+
let loan_path = Rc::new(LpVar(var_id));
3941
move_data.add_move(bccx.tcx, loan_path, decl_id, Declared);
4042
}
4143

@@ -131,7 +133,7 @@ pub fn gather_assignment(bccx: &BorrowckCtxt,
131133
move_data: &MoveData,
132134
assignment_id: ast::NodeId,
133135
assignment_span: Span,
134-
assignee_loan_path: @LoanPath,
136+
assignee_loan_path: Rc<LoanPath>,
135137
assignee_id: ast::NodeId) {
136138
move_data.add_assignment(bccx.tcx,
137139
assignee_loan_path,
@@ -145,7 +147,7 @@ pub fn gather_move_and_assignment(bccx: &BorrowckCtxt,
145147
move_data: &MoveData,
146148
assignment_id: ast::NodeId,
147149
assignment_span: Span,
148-
assignee_loan_path: @LoanPath,
150+
assignee_loan_path: Rc<LoanPath>,
149151
assignee_id: ast::NodeId) {
150152
move_data.add_assignment(bccx.tcx,
151153
assignee_loan_path,

0 commit comments

Comments
 (0)