]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs
Rollup merge of #53113 - kpp:more_docs_for_cow, r=GuillaumeGomez
[rust.git] / src / test / run-pass-valgrind / unsized-locals / long-live-the-unsized-temporary.rs
1 // Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![feature(unsized_locals)]
12
13 use std::fmt;
14
15 fn gen_foo() -> Box<fmt::Display> {
16     Box::new(Box::new("foo"))
17 }
18
19 fn foo(x: fmt::Display) {
20     assert_eq!(x.to_string(), "foo");
21 }
22
23 fn foo_indirect(x: fmt::Display) {
24     foo(x);
25 }
26
27 fn main() {
28     foo(*gen_foo());
29     foo_indirect(*gen_foo());
30
31     {
32         let x: fmt::Display = *gen_foo();
33         foo(x);
34     }
35
36     {
37         let x: fmt::Display = *gen_foo();
38         let y: fmt::Display = *gen_foo();
39         foo(x);
40         foo(y);
41     }
42
43     {
44         let mut cnt: usize = 3;
45         let x = loop {
46             let x: fmt::Display = *gen_foo();
47             if cnt == 0 {
48                 break x;
49             } else {
50                 cnt -= 1;
51             }
52         };
53         foo(x);
54     }
55
56     {
57         let x: fmt::Display = *gen_foo();
58         let x = if true {
59             x
60         } else {
61             *gen_foo()
62         };
63         foo(x);
64     }
65 }