diff options
| author | Masaki Hara <ackie.h.gmai@gmail.com> | 2018-05-29 00:12:55 +0900 |
|---|---|---|
| committer | Masaki Hara <ackie.h.gmai@gmail.com> | 2018-08-19 08:07:33 +0900 |
| commit | 800f2c13a3f4213648f301dcd4e10d80b1e6ea38 (patch) | |
| tree | bb789909096a22e3d46f36033eda4d4edd897e2f /src/test/run-pass-valgrind | |
| parent | e2b95cb70e2142aab82a40115d11ff54a975335e (diff) | |
| download | rust-800f2c13a3f4213648f301dcd4e10d80b1e6ea38.tar.gz rust-800f2c13a3f4213648f301dcd4e10d80b1e6ea38.zip | |
Implement simple codegen for unsized rvalues.
Diffstat (limited to 'src/test/run-pass-valgrind')
| -rw-r--r-- | src/test/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/src/test/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs b/src/test/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs new file mode 100644 index 00000000000..e1fda427b4e --- /dev/null +++ b/src/test/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs @@ -0,0 +1,65 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![feature(unsized_locals)] + +use std::fmt; + +fn gen_foo() -> Box<fmt::Display> { + Box::new(Box::new("foo")) +} + +fn foo(x: fmt::Display) { + assert_eq!(x.to_string(), "foo"); +} + +fn foo_indirect(x: fmt::Display) { + foo(x); +} + +fn main() { + foo(*gen_foo()); + foo_indirect(*gen_foo()); + + { + let x: fmt::Display = *gen_foo(); + foo(x); + } + + { + let x: fmt::Display = *gen_foo(); + let y: fmt::Display = *gen_foo(); + foo(x); + foo(y); + } + + { + let mut cnt: usize = 3; + let x = loop { + let x: fmt::Display = *gen_foo(); + if cnt == 0 { + break x; + } else { + cnt -= 1; + } + }; + foo(x); + } + + { + let x: fmt::Display = *gen_foo(); + let x = if true { + x + } else { + *gen_foo() + }; + foo(x); + } +} |
