]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/cleanup-shortcircuit.rs
Roll std::run into std::io::process
[rust.git] / src / test / run-pass / cleanup-shortcircuit.rs
1 // Copyright 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 // copyright 2014 the rust project developers. see the copyright
12 // file at the top-level directory of this distribution and at
13 // http://rust-lang.org/copyright.
14 //
15 // licensed under the apache license, version 2.0 <license-apache or
16 // http://www.apache.org/licenses/license-2.0> or the mit license
17 // <license-mit or http://opensource.org/licenses/mit>, at your
18 // option. this file may not be copied, modified, or distributed
19 // except according to those terms.
20
21 // Test that cleanups for the RHS of shorcircuiting operators work.
22
23 use std::os;
24
25 pub fn main() {
26     let args = os::args();
27
28     // Here, the rvalue `~"signal"` requires cleanup. Older versions
29     // of the code had a problem that the cleanup scope for this
30     // expression was the end of the `if`, and as the `~"signal"`
31     // expression was never evaluated, we wound up trying to clean
32     // uninitialized memory.
33
34     if args.len() >= 2 && args[1] == ~"signal" {
35         // Raise a segfault.
36         unsafe { *(0 as *mut int) = 0; }
37     }
38 }
39