]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/loop-no-reinit-needed-post-bot.rs
auto merge of #15247 : smenardpw/rust/patch-1, r=alexcrichton
[rust.git] / src / test / run-pass / loop-no-reinit-needed-post-bot.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 struct S;
12 // Ensure S is moved, not copied, on assignment.
13 impl Drop for S { fn drop(&mut self) { } }
14
15 // user-defined function "returning" bottom (i.e. no return at all).
16 fn my_fail() -> ! { loop {} }
17
18 pub fn step(f: bool) {
19     let mut g = S;
20     let mut i = 0i;
21     loop
22     {
23         if i > 10 { break; } else { i += 1; }
24
25         let _g = g;
26
27         if f {
28             // re-initialize g, but only before restarting loop.
29             g = S;
30             continue;
31         }
32
33         my_fail();
34
35         // we never get here, so we do not need to re-initialize g.
36     }
37 }
38
39 pub fn main() {
40     step(true);
41 }