Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/librustc/middle/borrowck/check_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
cmt = b;
}

mc::cat_downcast(b) |
mc::cat_interior(b, _) => {
if cmt.mutbl == mc::McInherited {
cmt = b;
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/middle/borrowck/gather_loans/lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ impl GuaranteeLifetimeContext {
}
}

mc::cat_downcast(base) |
mc::cat_deref(base, _, mc::uniq_ptr(*)) |
mc::cat_interior(base, _) => {
self.check(base, discr_scope)
Expand Down Expand Up @@ -303,6 +304,7 @@ impl GuaranteeLifetimeContext {
mc::cat_deref(*) => {
false
}
r @ mc::cat_downcast(*) |
r @ mc::cat_interior(*) |
r @ mc::cat_stack_upvar(*) |
r @ mc::cat_discr(*) => {
Expand Down Expand Up @@ -340,6 +342,7 @@ impl GuaranteeLifetimeContext {
mc::cat_deref(_, _, mc::region_ptr(_, r)) => {
r
}
mc::cat_downcast(cmt) |
mc::cat_deref(cmt, _, mc::uniq_ptr(*)) |
mc::cat_deref(cmt, _, mc::gc_ptr(*)) |
mc::cat_interior(cmt, _) |
Expand Down
19 changes: 6 additions & 13 deletions src/librustc/middle/borrowck/gather_loans/restrictions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,24 +80,17 @@ impl RestrictionsContext {
set: restrictions}])
}

mc::cat_interior(cmt_base, i @ mc::interior_variant(_)) => {
mc::cat_downcast(cmt_base) => {
// 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.
let result = self.compute(cmt_base, restrictions | RESTR_MUTATE);
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
self.compute(cmt_base, restrictions | RESTR_MUTATE)
}

mc::cat_interior(cmt_base, i @ mc::interior_tuple) |
mc::cat_interior(cmt_base, i @ mc::interior_anon_field) |
mc::cat_interior(cmt_base, i @ mc::interior_field(*)) |
mc::cat_interior(cmt_base, i @ mc::interior_index(*)) => {
// For all of these cases, overwriting the base would
// not change the type of the memory, so no additional
// restrictions are needed.
//
// FIXME(#5397) --- Mut fields are not treated soundly
// (hopefully they will just get phased out)
mc::cat_interior(cmt_base, i) => {
// Overwriting the base would not change the type of
// the memory, so no additional restrictions are
// needed.
let result = self.compute(cmt_base, restrictions);
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
}
Expand Down
28 changes: 15 additions & 13 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ pub enum LoanPath {

#[deriving(Eq)]
pub enum LoanPathElem {
LpDeref, // `*LV` in doc.rs
LpInterior(mc::interior_kind) // `LV.f` in doc.rs
LpDeref, // `*LV` in doc.rs
LpInterior(mc::InteriorKind) // `LV.f` in doc.rs
}

pub impl LoanPath {
Expand Down Expand Up @@ -280,6 +280,7 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> {
|&lp| @LpExtend(lp, cmt.mutbl, LpInterior(ik)))
}

mc::cat_downcast(cmt_base) |
mc::cat_stack_upvar(cmt_base) |
mc::cat_discr(cmt_base, _) => {
opt_loan_path(cmt_base)
Expand Down Expand Up @@ -616,24 +617,25 @@ pub impl BorrowckCtxt {
}
}

LpExtend(lp_base, _, LpInterior(mc::interior_field(fld))) => {
LpExtend(lp_base, _, LpInterior(mc::InteriorField(fname))) => {
self.append_loan_path_to_str_from_interior(lp_base, out);
str::push_char(out, '.');
str::push_str(out, *self.tcx.sess.intr().get(fld));
match fname {
mc::NamedField(fname) => {
str::push_char(out, '.');
str::push_str(out, *self.tcx.sess.intr().get(fname));
}
mc::PositionalField(idx) => {
str::push_char(out, '#'); // invent a notation here
str::push_str(out, idx.to_str());
}
}
}

LpExtend(lp_base, _, LpInterior(mc::interior_index(*))) => {
LpExtend(lp_base, _, LpInterior(mc::InteriorElement(_))) => {
self.append_loan_path_to_str_from_interior(lp_base, out);
str::push_str(out, "[]");
}

LpExtend(lp_base, _, LpInterior(mc::interior_tuple)) |
LpExtend(lp_base, _, LpInterior(mc::interior_anon_field)) |
LpExtend(lp_base, _, LpInterior(mc::interior_variant(_))) => {
self.append_loan_path_to_str_from_interior(lp_base, out);
str::push_str(out, ".(tuple)");
}

LpExtend(lp_base, _, LpDeref) => {
str::push_char(out, '*');
self.append_loan_path_to_str(lp_base, out);
Expand Down
Loading