diff options
| author | bors <bors@rust-lang.org> | 2015-04-15 21:05:16 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-04-15 21:05:16 +0000 |
| commit | 07f807d01f191ced1d7f4857c73fc57fbe31f421 (patch) | |
| tree | aef3faf7fd71fc8001954d0bf3f11f11ddc04685 /src/test | |
| parent | ce27d024ff16d297ce5e5bfb7cce11810e9c9b5e (diff) | |
| parent | 77bf827968d90594643ad0641161540ed1763730 (diff) | |
| download | rust-07f807d01f191ced1d7f4857c73fc57fbe31f421.tar.gz rust-07f807d01f191ced1d7f4857c73fc57fbe31f421.zip | |
Auto merge of #24330 - pnkfelix:issue-24267, r=nikomatsakis
Extend rustc::middle::dataflow to allow filtering kills from flow-exits.
Fix borrowck analysis so that it will not treat a break that pops through an assignment
```rust
x = { ... break; ... }
```
as a kill of the "moved-out" bit for `x`.
Fix #24267.
[breaking-change], but really, its only breaking code that was already buggy.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/compile-fail/issue-24267-flow-exit.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/test/compile-fail/issue-24267-flow-exit.rs b/src/test/compile-fail/issue-24267-flow-exit.rs new file mode 100644 index 00000000000..4aca6bf38e1 --- /dev/null +++ b/src/test/compile-fail/issue-24267-flow-exit.rs @@ -0,0 +1,29 @@ +// Copyright 2015 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. + +// Ensure that we reject code when a nonlocal exit (`break`, +// `continue`) causes us to pop over a needed assignment. + +pub fn main() { + foo1(); + foo2(); +} + +pub fn foo1() { + let x: i32; + loop { x = break; } + println!("{}", x); //~ ERROR use of possibly uninitialized variable: `x` +} + +pub fn foo2() { + let x: i32; + for _ in 0..10 { x = continue; } + println!("{}", x); //~ ERROR use of possibly uninitialized variable: `x` +} |
