]> git.lizzy.rs Git - rust.git/blob - tests/ui/cleanup-shortcircuit.rs
Rollup merge of #106664 - chenyukang:yukang/fix-106597-remove-lseek, r=cuviper
[rust.git] / tests / 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 #![allow(deref_nullptr)]
7
8
9 use std::env;
10
11 pub fn main() {
12     let args: Vec<String> = env::args().collect();
13
14     // Here, the rvalue `"signal".to_string()` requires cleanup. Older versions
15     // of the code had a problem that the cleanup scope for this
16     // expression was the end of the `if`, and as the `"signal".to_string()`
17     // expression was never evaluated, we wound up trying to clean
18     // uninitialized memory.
19
20     if args.len() >= 2 && args[1] == "signal" {
21         // Raise a segfault.
22         unsafe { *std::ptr::null_mut::<isize>() = 0; }
23     }
24 }