2014-06-10 15:54:13 -05:00
|
|
|
// Copyright 2012 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 #12512.
|
|
|
|
|
2015-03-22 15:13:15 -05:00
|
|
|
// pretty-expanded FIXME #23616
|
|
|
|
|
2014-06-10 15:54:13 -05:00
|
|
|
fn main() {
|
|
|
|
let mut foo = Vec::new();
|
2015-01-31 11:20:46 -06:00
|
|
|
'foo: for i in &[1, 2, 3] {
|
make `for PAT in ITER_EXPR { ... }` a terminating-scope for ITER_EXPR.
In effect, temporary anonymous values created during the evaluation of
ITER_EXPR no longer not live for the entirety of the block surrounding
the for-loop; instead they only live for the extent of the for-loop
itself, and no longer.
----
There is one case I know of that this breaks, demonstrated to me by
niko (but it is also a corner-case that is useless in practice). Here
is that case:
```
fn main() {
let mut foo: Vec<&i8> = Vec::new();
for i in &[1, 2, 3] { foo.push(i) }
}
```
Note that if you add any code following the for-loop above, or even a
semicolon to the end of it, then the code will stop compiling (i.e.,
it gathers a vector of references but the gathered vector cannot
actually be used.)
(The above code, despite being useless, did occur in one run-pass test
by accident; that test is updated here to accommodate the new
striction.)
----
So, technically this is a:
[breaking-change]
2015-02-04 06:24:44 -06:00
|
|
|
foo.push(*i);
|
2014-06-10 15:54:13 -05:00
|
|
|
}
|
|
|
|
}
|