Skip to content

Commit 5ca383b

Browse files
committed
Distinguish tuple elements by index in mem_categorization. Fixes #5362.
1 parent ff08198 commit 5ca383b

File tree

8 files changed

+246
-81
lines changed

8 files changed

+246
-81
lines changed

src/librustc/middle/borrowck/check_loans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
400400
cmt = b;
401401
}
402402

403+
mc::cat_downcast(b) |
403404
mc::cat_interior(b, _) => {
404405
if cmt.mutbl == mc::McInherited {
405406
cmt = b;

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ impl GuaranteeLifetimeContext {
105105
}
106106
}
107107

108+
mc::cat_downcast(base) |
108109
mc::cat_deref(base, _, mc::uniq_ptr(*)) |
109110
mc::cat_interior(base, _) => {
110111
self.check(base, discr_scope)
@@ -303,6 +304,7 @@ impl GuaranteeLifetimeContext {
303304
mc::cat_deref(*) => {
304305
false
305306
}
307+
r @ mc::cat_downcast(*) |
306308
r @ mc::cat_interior(*) |
307309
r @ mc::cat_stack_upvar(*) |
308310
r @ mc::cat_discr(*) => {
@@ -340,6 +342,7 @@ impl GuaranteeLifetimeContext {
340342
mc::cat_deref(_, _, mc::region_ptr(_, r)) => {
341343
r
342344
}
345+
mc::cat_downcast(cmt) |
343346
mc::cat_deref(cmt, _, mc::uniq_ptr(*)) |
344347
mc::cat_deref(cmt, _, mc::gc_ptr(*)) |
345348
mc::cat_interior(cmt, _) |

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

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -80,24 +80,17 @@ impl RestrictionsContext {
8080
set: restrictions}])
8181
}
8282

83-
mc::cat_interior(cmt_base, i @ mc::interior_variant(_)) => {
83+
mc::cat_downcast(cmt_base) => {
8484
// When we borrow the interior of an enum, we have to
8585
// ensure the enum itself is not mutated, because that
8686
// could cause the type of the memory to change.
87-
let result = self.compute(cmt_base, restrictions | RESTR_MUTATE);
88-
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
87+
self.compute(cmt_base, restrictions | RESTR_MUTATE)
8988
}
9089

91-
mc::cat_interior(cmt_base, i @ mc::interior_tuple) |
92-
mc::cat_interior(cmt_base, i @ mc::interior_anon_field) |
93-
mc::cat_interior(cmt_base, i @ mc::interior_field(*)) |
94-
mc::cat_interior(cmt_base, i @ mc::interior_index(*)) => {
95-
// For all of these cases, overwriting the base would
96-
// not change the type of the memory, so no additional
97-
// restrictions are needed.
98-
//
99-
// FIXME(#5397) --- Mut fields are not treated soundly
100-
// (hopefully they will just get phased out)
90+
mc::cat_interior(cmt_base, i) => {
91+
// Overwriting the base would not change the type of
92+
// the memory, so no additional restrictions are
93+
// needed.
10194
let result = self.compute(cmt_base, restrictions);
10295
self.extend(result, cmt.mutbl, LpInterior(i), restrictions)
10396
}

src/librustc/middle/borrowck/mod.rs

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ pub enum LoanPath {
236236

237237
#[deriving(Eq)]
238238
pub enum LoanPathElem {
239-
LpDeref, // `*LV` in doc.rs
240-
LpInterior(mc::interior_kind) // `LV.f` in doc.rs
239+
LpDeref, // `*LV` in doc.rs
240+
LpInterior(mc::InteriorKind) // `LV.f` in doc.rs
241241
}
242242

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

283+
mc::cat_downcast(cmt_base) |
283284
mc::cat_stack_upvar(cmt_base) |
284285
mc::cat_discr(cmt_base, _) => {
285286
opt_loan_path(cmt_base)
@@ -616,24 +617,25 @@ pub impl BorrowckCtxt {
616617
}
617618
}
618619

619-
LpExtend(lp_base, _, LpInterior(mc::interior_field(fld))) => {
620+
LpExtend(lp_base, _, LpInterior(mc::InteriorField(fname))) => {
620621
self.append_loan_path_to_str_from_interior(lp_base, out);
621-
str::push_char(out, '.');
622-
str::push_str(out, *self.tcx.sess.intr().get(fld));
622+
match fname {
623+
mc::NamedField(fname) => {
624+
str::push_char(out, '.');
625+
str::push_str(out, *self.tcx.sess.intr().get(fname));
626+
}
627+
mc::PositionalField(idx) => {
628+
str::push_char(out, '#'); // invent a notation here
629+
str::push_str(out, idx.to_str());
630+
}
631+
}
623632
}
624633

625-
LpExtend(lp_base, _, LpInterior(mc::interior_index(*))) => {
634+
LpExtend(lp_base, _, LpInterior(mc::InteriorElement(_))) => {
626635
self.append_loan_path_to_str_from_interior(lp_base, out);
627636
str::push_str(out, "[]");
628637
}
629638

630-
LpExtend(lp_base, _, LpInterior(mc::interior_tuple)) |
631-
LpExtend(lp_base, _, LpInterior(mc::interior_anon_field)) |
632-
LpExtend(lp_base, _, LpInterior(mc::interior_variant(_))) => {
633-
self.append_loan_path_to_str_from_interior(lp_base, out);
634-
str::push_str(out, ".(tuple)");
635-
}
636-
637639
LpExtend(lp_base, _, LpDeref) => {
638640
str::push_char(out, '*');
639641
self.append_loan_path_to_str(lp_base, out);

0 commit comments

Comments
 (0)