Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

auto: librustc: Allow mutable box substructure to be borrowed without requirin... #4826

Closed
wants to merge 1 commit into from
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
2 changes: 1 addition & 1 deletion src/librustc/middle/borrowck/gather_loans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/middle/borrowck/preserve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions src/test/run-pass/borrowck-wg-mut-box-substructure.rs
Original file line number Diff line number Diff line change
@@ -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());
}
}