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