Skip to content

Commit e35db1a

Browse files
committed
Reconcile treatment of &mut with the docs
1 parent bf1647c commit e35db1a

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -657,12 +657,12 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
657657
let move_err = this.analyze_move_out_from_cmt(cmt);
658658
match move_err {
659659
MoveOk => {}
660-
MoveWhileBorrowed(loan_path, loan_span) => {
660+
MoveWhileBorrowed(move_path, loan_path, loan_span) => {
661661
this.bccx.span_err(
662662
cap_var.span,
663663
fmt!("cannot move `%s` into closure \
664664
because it is borrowed",
665-
this.bccx.loan_path_to_str(loan_path)));
665+
this.bccx.loan_path_to_str(move_path)));
666666
this.bccx.span_note(
667667
loan_span,
668668
fmt!("borrow of `%s` occurs here",

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

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn compute_restrictions(bccx: @BorrowckCtxt,
3333
cmt_original: cmt
3434
};
3535

36-
ctxt.compute(cmt, restr)
36+
ctxt.restrict(cmt, restr)
3737
}
3838

3939
///////////////////////////////////////////////////////////////////////////
@@ -50,9 +50,9 @@ impl RestrictionsContext {
5050
self.bccx.tcx
5151
}
5252

53-
fn compute(&self,
54-
cmt: mc::cmt,
55-
restrictions: RestrictionSet) -> RestrictionResult {
53+
fn restrict(&self,
54+
cmt: mc::cmt,
55+
restrictions: RestrictionSet) -> RestrictionResult {
5656

5757
// Check for those cases where we cannot control the aliasing
5858
// and make sure that we are not being asked to.
@@ -86,7 +86,9 @@ impl RestrictionsContext {
8686
// When we borrow the interior of an enum, we have to
8787
// ensure the enum itself is not mutated, because that
8888
// could cause the type of the memory to change.
89-
self.compute(cmt_base, restrictions | RESTR_MUTATE | RESTR_CLAIM)
89+
self.restrict(
90+
cmt_base,
91+
restrictions | RESTR_MUTATE | RESTR_CLAIM)
9092
}
9193

9294
mc::cat_interior(cmt_base, i) => {
@@ -95,7 +97,7 @@ impl RestrictionsContext {
9597
// Overwriting the base would not change the type of
9698
// the memory, so no additional restrictions are
9799
// needed.
98-
let result = self.compute(cmt_base, restrictions);
100+
let result = self.restrict(cmt_base, restrictions);
99101
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
100102
}
101103

@@ -105,7 +107,7 @@ impl RestrictionsContext {
105107
// When we borrow the interior of an owned pointer, we
106108
// cannot permit the base to be mutated, because that
107109
// would cause the unique pointer to be freed.
108-
let result = self.compute(
110+
let result = self.restrict(
109111
cmt_base,
110112
restrictions | RESTR_MUTATE | RESTR_CLAIM);
111113
self.extend(result, cmt.mutbl, LpDeref, restrictions)
@@ -180,16 +182,15 @@ impl RestrictionsContext {
180182
// mutability, we can only prevent mutation or prevent
181183
// freezing if it is not aliased. Therefore, in such
182184
// cases we restrict aliasing on `cmt_base`.
183-
if restrictions.intersects(RESTR_MUTATE |
184-
RESTR_CLAIM |
185-
RESTR_FREEZE) {
185+
if restrictions != RESTR_EMPTY {
186186
// R-Deref-Mut-Borrowed-1
187-
let result = self.compute(cmt_base, restrictions | RESTR_ALIAS);
187+
let result = self.restrict(
188+
cmt_base,
189+
RESTR_ALIAS | RESTR_MUTATE | RESTR_CLAIM);
188190
self.extend(result, cmt.mutbl, LpDeref, restrictions)
189191
} else {
190192
// R-Deref-Mut-Borrowed-2
191-
let result = self.compute(cmt_base, restrictions);
192-
self.extend(result, cmt.mutbl, LpDeref, restrictions)
193+
Safe
193194
}
194195
}
195196

@@ -200,7 +201,7 @@ impl RestrictionsContext {
200201

201202
mc::cat_stack_upvar(cmt_base) |
202203
mc::cat_discr(cmt_base, _) => {
203-
self.compute(cmt_base, restrictions)
204+
self.restrict(cmt_base, restrictions)
204205
}
205206
}
206207
}

src/librustc/middle/borrowck/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ pub struct Restriction {
315315
set: RestrictionSet
316316
}
317317

318+
#[deriving(Eq)]
318319
pub struct RestrictionSet {
319320
bits: u32
320321
}

0 commit comments

Comments
 (0)