terminate-in-initializer.rs 1.0 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
// 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.

D
Daniel Micay 已提交
11

12
// Issue #787
13
// Don't try to clean up uninitialized locals
14

15 16
use std::task;

E
Eduard Burtescu 已提交
17
fn test_break() { loop { let _x: Box<int> = break; } }
18

E
Eduard Burtescu 已提交
19
fn test_cont() { let mut i = 0i; while i < 1 { i += 1; let _x: Box<int> = continue; } }
20

E
Eduard Burtescu 已提交
21
fn test_ret() { let _x: Box<int> = return; }
22 23

fn test_fail() {
E
Eduard Burtescu 已提交
24
    fn f() { let _x: Box<int> = fail!(); }
25
    task::try(proc() f() );
26 27 28
}

fn test_fail_indirect() {
29
    fn f() -> ! { fail!(); }
E
Eduard Burtescu 已提交
30
    fn g() { let _x: Box<int> = f(); }
31
    task::try(proc() g() );
32 33
}

34
pub fn main() {
35 36 37 38 39
    test_break();
    test_cont();
    test_ret();
    test_fail();
    test_fail_indirect();
B
Brian Anderson 已提交
40
}