]> git.lizzy.rs Git - rust.git/blob - tests/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs
Rollup merge of #106692 - eggyal:mv-binary_heap.rs-binary_heap/mod.rs, r=Mark-Simulacrum
[rust.git] / tests / run-pass-valgrind / unsized-locals / long-live-the-unsized-temporary.rs
1 #![allow(incomplete_features)]
2 #![feature(unsized_locals, unsized_fn_params)]
3
4 use std::fmt;
5
6 fn gen_foo() -> Box<fmt::Display> {
7     Box::new(Box::new("foo"))
8 }
9
10 fn foo(x: fmt::Display) {
11     assert_eq!(x.to_string(), "foo");
12 }
13
14 fn foo_indirect(x: fmt::Display) {
15     foo(x);
16 }
17
18 fn main() {
19     foo(*gen_foo());
20     foo_indirect(*gen_foo());
21
22     {
23         let x: fmt::Display = *gen_foo();
24         foo(x);
25     }
26
27     {
28         let x: fmt::Display = *gen_foo();
29         let y: fmt::Display = *gen_foo();
30         foo(x);
31         foo(y);
32     }
33
34     {
35         let mut cnt: usize = 3;
36         let x = loop {
37             let x: fmt::Display = *gen_foo();
38             if cnt == 0 {
39                 break x;
40             } else {
41                 cnt -= 1;
42             }
43         };
44         foo(x);
45     }
46
47     {
48         let x: fmt::Display = *gen_foo();
49         let x = if true { x } else { *gen_foo() };
50         foo(x);
51     }
52 }