Reconcile treatment of &mut with the docs
This commit is contained in:
parent
bf1647c92a
commit
e35db1ab35
|
@ -657,12 +657,12 @@ fn check_loans_in_fn<'a>(fk: &visit::fn_kind,
|
|||
let move_err = this.analyze_move_out_from_cmt(cmt);
|
||||
match move_err {
|
||||
MoveOk => {}
|
||||
MoveWhileBorrowed(loan_path, loan_span) => {
|
||||
MoveWhileBorrowed(move_path, loan_path, loan_span) => {
|
||||
this.bccx.span_err(
|
||||
cap_var.span,
|
||||
fmt!("cannot move `%s` into closure \
|
||||
because it is borrowed",
|
||||
this.bccx.loan_path_to_str(loan_path)));
|
||||
this.bccx.loan_path_to_str(move_path)));
|
||||
this.bccx.span_note(
|
||||
loan_span,
|
||||
fmt!("borrow of `%s` occurs here",
|
||||
|
|
|
@ -33,7 +33,7 @@ pub fn compute_restrictions(bccx: @BorrowckCtxt,
|
|||
cmt_original: cmt
|
||||
};
|
||||
|
||||
ctxt.compute(cmt, restr)
|
||||
ctxt.restrict(cmt, restr)
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
@ -50,9 +50,9 @@ impl RestrictionsContext {
|
|||
self.bccx.tcx
|
||||
}
|
||||
|
||||
fn compute(&self,
|
||||
cmt: mc::cmt,
|
||||
restrictions: RestrictionSet) -> RestrictionResult {
|
||||
fn restrict(&self,
|
||||
cmt: mc::cmt,
|
||||
restrictions: RestrictionSet) -> RestrictionResult {
|
||||
|
||||
// Check for those cases where we cannot control the aliasing
|
||||
// and make sure that we are not being asked to.
|
||||
|
@ -86,7 +86,9 @@ impl RestrictionsContext {
|
|||
// When we borrow the interior of an enum, we have to
|
||||
// ensure the enum itself is not mutated, because that
|
||||
// could cause the type of the memory to change.
|
||||
self.compute(cmt_base, restrictions | RESTR_MUTATE | RESTR_CLAIM)
|
||||
self.restrict(
|
||||
cmt_base,
|
||||
restrictions | RESTR_MUTATE | RESTR_CLAIM)
|
||||
}
|
||||
|
||||
mc::cat_interior(cmt_base, i) => {
|
||||
|
@ -95,7 +97,7 @@ impl RestrictionsContext {
|
|||
// Overwriting the base would not change the type of
|
||||
// the memory, so no additional restrictions are
|
||||
// needed.
|
||||
let result = self.compute(cmt_base, restrictions);
|
||||
let result = self.restrict(cmt_base, restrictions);
|
||||
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
|
||||
}
|
||||
|
||||
|
@ -105,7 +107,7 @@ impl RestrictionsContext {
|
|||
// When we borrow the interior of an owned pointer, we
|
||||
// cannot permit the base to be mutated, because that
|
||||
// would cause the unique pointer to be freed.
|
||||
let result = self.compute(
|
||||
let result = self.restrict(
|
||||
cmt_base,
|
||||
restrictions | RESTR_MUTATE | RESTR_CLAIM);
|
||||
self.extend(result, cmt.mutbl, LpDeref, restrictions)
|
||||
|
@ -180,16 +182,15 @@ impl RestrictionsContext {
|
|||
// mutability, we can only prevent mutation or prevent
|
||||
// freezing if it is not aliased. Therefore, in such
|
||||
// cases we restrict aliasing on `cmt_base`.
|
||||
if restrictions.intersects(RESTR_MUTATE |
|
||||
RESTR_CLAIM |
|
||||
RESTR_FREEZE) {
|
||||
if restrictions != RESTR_EMPTY {
|
||||
// R-Deref-Mut-Borrowed-1
|
||||
let result = self.compute(cmt_base, restrictions | RESTR_ALIAS);
|
||||
let result = self.restrict(
|
||||
cmt_base,
|
||||
RESTR_ALIAS | RESTR_MUTATE | RESTR_CLAIM);
|
||||
self.extend(result, cmt.mutbl, LpDeref, restrictions)
|
||||
} else {
|
||||
// R-Deref-Mut-Borrowed-2
|
||||
let result = self.compute(cmt_base, restrictions);
|
||||
self.extend(result, cmt.mutbl, LpDeref, restrictions)
|
||||
Safe
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -200,7 +201,7 @@ impl RestrictionsContext {
|
|||
|
||||
mc::cat_stack_upvar(cmt_base) |
|
||||
mc::cat_discr(cmt_base, _) => {
|
||||
self.compute(cmt_base, restrictions)
|
||||
self.restrict(cmt_base, restrictions)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -315,6 +315,7 @@ pub struct Restriction {
|
|||
set: RestrictionSet
|
||||
}
|
||||
|
||||
#[deriving(Eq)]
|
||||
pub struct RestrictionSet {
|
||||
bits: u32
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue