]> git.lizzy.rs Git - rust.git/blob - src/test/ui/cleanup-shortcircuit.rs
Detect pub fn attr wrong order like `async pub`
[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
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 { *std::ptr::null_mut::<isize>() = 0; }
20     }
21 }