Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
librustc: Use the correct categorized mutable type for the pattern in
`for` loop heads. This breaks code like: let x = Some(box 1i); for &a in x.iter() { } Change this code to obey the borrow checking rules. For example: let x = Some(box 1i); for &ref a in x.iter() { } Closes #16205. [breaking-change]
- Loading branch information
Showing
2 changed files
with
43 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/test/compile-fail/borrowck-for-loop-correct-cmt-for-pattern.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// Issue #16205. | ||
|
||
struct Foo { | ||
a: [Box<int>, ..3], | ||
} | ||
|
||
fn main() { | ||
let mut y = 1i; | ||
let x = Some(&mut y); | ||
for &a in x.iter() { //~ ERROR cannot move out | ||
} | ||
|
||
let f = Foo { | ||
a: [box 3, box 4, box 5], | ||
}; | ||
for &a in f.a.iter() { //~ ERROR cannot move out | ||
} | ||
|
||
let x = Some(box 1i); | ||
for &a in x.iter() { //~ ERROR cannot move out | ||
} | ||
} | ||
|
7579185
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
saw approval from nikomatsakis
at pcwalton@7579185
7579185
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merging pcwalton/rust/borrowck-for-moves = 7579185 into auto
7579185
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pcwalton/rust/borrowck-for-moves = 7579185 merged ok, testing candidate = ee87234
7579185
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
all tests pass:
success: http://buildbot.rust-lang.org/builders/auto-mac-32-opt/builds/799
success: http://buildbot.rust-lang.org/builders/auto-mac-64-opt/builds/799
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-c/builds/798
success: http://buildbot.rust-lang.org/builders/auto-mac-64-nopt-t/builds/799
success: http://buildbot.rust-lang.org/builders/auto-linux-32-opt/builds/795
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-c/builds/796
success: http://buildbot.rust-lang.org/builders/auto-linux-32-nopt-t/builds/795
success: http://buildbot.rust-lang.org/builders/auto-linux-64-opt/builds/801
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-c/builds/796
success: http://buildbot.rust-lang.org/builders/auto-linux-64-nopt-t/builds/795
success: http://buildbot.rust-lang.org/builders/auto-linux-64-x-android-t/builds/798
success: http://buildbot.rust-lang.org/builders/auto-win-32-opt/builds/796
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-t/builds/796
success: http://buildbot.rust-lang.org/builders/auto-win-32-nopt-c/builds/797
7579185
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fast-forwarding master to auto = ee87234