Skip to content

Commit 32e30aa

Browse files
committed
auto merge of #6576 : nikomatsakis/rust/issue-5362-tuple-indices, r=graydon
r? @pcwalton
2 parents 2460967 + 5ca383b commit 32e30aa

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
@@ -343,6 +343,7 @@ pub impl<'self> CheckLoanCtxt<'self> {
343343
cmt = b;
344344
}
345345

346+
mc::cat_downcast(b) |
346347
mc::cat_interior(b, _) => {
347348
if cmt.mutbl == mc::McInherited {
348349
cmt = b;

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

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

107+
mc::cat_downcast(base) |
107108
mc::cat_deref(base, _, mc::uniq_ptr(*)) |
108109
mc::cat_interior(base, _) => {
109110
self.check(base, discr_scope)
@@ -302,6 +303,7 @@ impl GuaranteeLifetimeContext {
302303
mc::cat_deref(*) => {
303304
false
304305
}
306+
r @ mc::cat_downcast(*) |
305307
r @ mc::cat_interior(*) |
306308
r @ mc::cat_stack_upvar(*) |
307309
r @ mc::cat_discr(*) => {
@@ -339,6 +341,7 @@ impl GuaranteeLifetimeContext {
339341
mc::cat_deref(_, _, mc::region_ptr(_, r)) => {
340342
r
341343
}
344+
mc::cat_downcast(cmt) |
342345
mc::cat_deref(cmt, _, mc::uniq_ptr(*)) |
343346
mc::cat_deref(cmt, _, mc::gc_ptr(*)) |
344347
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
@@ -79,24 +79,17 @@ impl RestrictionsContext {
7979
set: restrictions}])
8080
}
8181

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

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

src/librustc/middle/borrowck/mod.rs

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

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

239239
pub impl LoanPath {
@@ -276,6 +276,7 @@ pub fn opt_loan_path(cmt: mc::cmt) -> Option<@LoanPath> {
276276
|&lp| @LpExtend(lp, cmt.mutbl, LpInterior(ik)))
277277
}
278278

279+
mc::cat_downcast(cmt_base) |
279280
mc::cat_stack_upvar(cmt_base) |
280281
mc::cat_discr(cmt_base, _) => {
281282
opt_loan_path(cmt_base)
@@ -612,24 +613,25 @@ pub impl BorrowckCtxt {
612613
}
613614
}
614615

615-
LpExtend(lp_base, _, LpInterior(mc::interior_field(fld))) => {
616+
LpExtend(lp_base, _, LpInterior(mc::InteriorField(fname))) => {
616617
self.append_loan_path_to_str_from_interior(lp_base, out);
617-
str::push_char(out, '.');
618-
str::push_str(out, *self.tcx.sess.intr().get(fld));
618+
match fname {
619+
mc::NamedField(fname) => {
620+
str::push_char(out, '.');
621+
str::push_str(out, *self.tcx.sess.intr().get(fname));
622+
}
623+
mc::PositionalField(idx) => {
624+
str::push_char(out, '#'); // invent a notation here
625+
str::push_str(out, idx.to_str());
626+
}
627+
}
619628
}
620629

621-
LpExtend(lp_base, _, LpInterior(mc::interior_index(*))) => {
630+
LpExtend(lp_base, _, LpInterior(mc::InteriorElement(_))) => {
622631
self.append_loan_path_to_str_from_interior(lp_base, out);
623632
str::push_str(out, "[]");
624633
}
625634

626-
LpExtend(lp_base, _, LpInterior(mc::interior_tuple)) |
627-
LpExtend(lp_base, _, LpInterior(mc::interior_anon_field)) |
628-
LpExtend(lp_base, _, LpInterior(mc::interior_variant(_))) => {
629-
self.append_loan_path_to_str_from_interior(lp_base, out);
630-
str::push_str(out, ".(tuple)");
631-
}
632-
633635
LpExtend(lp_base, _, LpDeref) => {
634636
str::push_char(out, '*');
635637
self.append_loan_path_to_str(lp_base, out);

0 commit comments

Comments
 (0)