]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/cleanup-shortcircuit.rs
Rollup merge of #61499 - varkor:issue-53457, r=oli-obk
[rust.git] / src / test / run-pass / cleanup-shortcircuit.rs
1 // Test that cleanups for the RHS of shortcircuiting operators work.
2
3 // pretty-expanded FIXME #23616
4 // ignore-cloudabi no std::env support
5
6 use std::env;
7
8 pub fn main() {
9     let args: Vec<String> = env::args().collect();
10
11     // Here, the rvalue `"signal".to_string()` requires cleanup. Older versions
12     // of the code had a problem that the cleanup scope for this
13     // expression was the end of the `if`, and as the `"signal".to_string()`
14     // expression was never evaluated, we wound up trying to clean
15     // uninitialized memory.
16
17     if args.len() >= 2 && args[1] == "signal" {
18         // Raise a segfault.
19         unsafe { *(0 as *mut isize) = 0; }
20     }
21 }