]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issues/issue-30530.rs
New upstream version 1.37.0+dfsg1
[rustc.git] / src / test / run-pass / issues / issue-30530.rs
1 // run-pass
2 // Regression test for Issue #30530: alloca's created for storing
3 // intermediate scratch values during brace-less match arms need to be
4 // initialized with their drop-flag set to "dropped" (or else we end
5 // up running the destructors on garbage data at the end of the
6 // function).
7
8 pub enum Handler {
9 Default,
10 #[allow(dead_code)]
11 Custom(*mut Box<dyn Fn()>),
12 }
13
14 fn main() {
15 #[allow(unused_must_use)] {
16 take(Handler::Default, Box::new(main));
17 }
18 }
19
20 #[inline(never)]
21 pub fn take(h: Handler, f: Box<dyn Fn()>) -> Box<dyn Fn()> {
22 unsafe {
23 match h {
24 Handler::Custom(ptr) => *Box::from_raw(ptr),
25 Handler::Default => f,
26 }
27 }
28 }