diff --git a/src/librustc/middle/borrowck/gather_loans.rs b/src/librustc/middle/borrowck/gather_loans.rs index 8029b4c271394..e347a7d895926 100644 --- a/src/librustc/middle/borrowck/gather_loans.rs +++ b/src/librustc/middle/borrowck/gather_loans.rs @@ -455,7 +455,7 @@ impl gather_loan_ctxt { if req_mutbl == m_imm { // if this is an @mut box, then it's generally OK to borrow as // &imm; this will result in a write guard - if cmt.cat.is_mutable_box() { + if cmt.cat.derefs_through_mutable_box() { Ok(PcOk) } else { // you can treat mutable things as imm if you are pure diff --git a/src/librustc/middle/borrowck/preserve.rs b/src/librustc/middle/borrowck/preserve.rs index 1946ba09ec7bf..a996a71a29f7f 100644 --- a/src/librustc/middle/borrowck/preserve.rs +++ b/src/librustc/middle/borrowck/preserve.rs @@ -191,6 +191,8 @@ impl PreserveCtxt { // live, so we must root the pointer (i.e., inc the ref // count) for the duration of the loan. debug!("base.mutbl = %?", self.bccx.mut_to_str(base.mutbl)); + debug!("derefs through mutable box? %?", + cmt.cat.derefs_through_mutable_box()); if cmt.cat.derefs_through_mutable_box() { self.attempt_root(cmt, base, derefs) } else if base.mutbl == m_imm { diff --git a/src/test/run-pass/borrowck-wg-mut-box-substructure.rs b/src/test/run-pass/borrowck-wg-mut-box-substructure.rs new file mode 100644 index 0000000000000..ff044b4f18788 --- /dev/null +++ b/src/test/run-pass/borrowck-wg-mut-box-substructure.rs @@ -0,0 +1,11 @@ +struct Foo { + x: ~[int] +} + +fn main() { + let x = @mut Foo { x: ~[ 1, 2, 3, 4, 5 ] }; + for x.x.each |x| { + io::println(x.to_str()); + } +} +