]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/cleanup-shortcircuit.rs
rustdoc: Replace no-pretty-expanded with pretty-expanded
[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 shortcircuiting operators work.
22
23 // pretty-expanded FIXME #23616
24
25 use std::env;
26
27 pub fn main() {
28     let args: Vec<String> = env::args().collect();
29
30     // Here, the rvalue `"signal".to_string()` requires cleanup. Older versions
31     // of the code had a problem that the cleanup scope for this
32     // expression was the end of the `if`, and as the `"signal".to_string()`
33     // expression was never evaluated, we wound up trying to clean
34     // uninitialized memory.
35
36     if args.len() >= 2 && args[1] == "signal" {
37         // Raise a segfault.
38         unsafe { *(0 as *mut int) = 0; }
39     }
40 }