Skip to content

Commit a9f5ab1

Browse files
committedFeb 7, 2013
librustc: Allow mutable box substructure to be borrowed without requiring purity. Closes #4825.
1 parent f13ea41 commit a9f5ab1

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed
 

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl gather_loan_ctxt {
455455
if req_mutbl == m_imm {
456456
// if this is an @mut box, then it's generally OK to borrow as
457457
// &imm; this will result in a write guard
458-
if cmt.cat.is_mutable_box() {
458+
if cmt.cat.derefs_through_mutable_box() {
459459
Ok(PcOk)
460460
} else {
461461
// you can treat mutable things as imm if you are pure

‎src/librustc/middle/borrowck/preserve.rs

+2
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,8 @@ impl PreserveCtxt {
191191
// live, so we must root the pointer (i.e., inc the ref
192192
// count) for the duration of the loan.
193193
debug!("base.mutbl = %?", self.bccx.mut_to_str(base.mutbl));
194+
debug!("derefs through mutable box? %?",
195+
cmt.cat.derefs_through_mutable_box());
194196
if cmt.cat.derefs_through_mutable_box() {
195197
self.attempt_root(cmt, base, derefs)
196198
} else if base.mutbl == m_imm {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
struct Foo {
2+
x: ~[int]
3+
}
4+
5+
fn main() {
6+
let x = @mut Foo { x: ~[ 1, 2, 3, 4, 5 ] };
7+
for x.x.each |x| {
8+
io::println(x.to_str());
9+
}
10+
}
11+

4 commit comments

Comments
 (4)

bors commented on Feb 9, 2013

@bors
Collaborator

saw approval from catamorphism
at pcwalton@a9f5ab1

bors commented on Feb 9, 2013

@bors
Collaborator

merging pcwalton/rust/inhtwama-substructure = a9f5ab1 into auto

bors commented on Feb 9, 2013

@bors
Collaborator

pcwalton/rust/inhtwama-substructure = a9f5ab1 merged ok, testing candidate = 2763af07

bors commented on Feb 9, 2013

@bors
Collaborator
Please sign in to comment.