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 | |
| parent | e2b95cb70e2142aab82a40115d11ff54a975335e (diff) | |
| download | rust-800f2c13a3f4213648f301dcd4e10d80b1e6ea38.tar.gz rust-800f2c13a3f4213648f301dcd4e10d80b1e6ea38.zip | |
Implement simple codegen for unsized rvalues.
Diffstat (limited to 'src/test')
5 files changed, 163 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); + } +} diff --git a/src/test/run-pass/unsized-locals/reference-unsized-locals.rs b/src/test/run-pass/unsized-locals/reference-unsized-locals.rs new file mode 100644 index 00000000000..6ed39a78648 --- /dev/null +++ b/src/test/run-pass/unsized-locals/reference-unsized-locals.rs @@ -0,0 +1,17 @@ +// 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)] + +fn main() { + let foo: Box<[u8]> = Box::new(*b"foo"); + let foo: [u8] = *foo; + assert_eq!(&foo, b"foo" as &[u8]); +} diff --git a/src/test/run-pass/unsized-locals/simple-unsized-locals.rs b/src/test/run-pass/unsized-locals/simple-unsized-locals.rs new file mode 100644 index 00000000000..0b1aa6225eb --- /dev/null +++ b/src/test/run-pass/unsized-locals/simple-unsized-locals.rs @@ -0,0 +1,16 @@ +// 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)] + +fn main() { + let foo: Box<[u8]> = Box::new(*b"foo"); + let _foo: [u8] = *foo; +} diff --git a/src/test/run-pass/unsized-locals/unsized-exprs.rs b/src/test/run-pass/unsized-locals/unsized-exprs.rs new file mode 100644 index 00000000000..9a5e534db25 --- /dev/null +++ b/src/test/run-pass/unsized-locals/unsized-exprs.rs @@ -0,0 +1,45 @@ +// 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_tuple_coercion, unsized_locals)] + +struct A<X: ?Sized>(X); + +fn udrop<T: ?Sized>(_x: T) {} +fn foo() -> Box<[u8]> { + Box::new(*b"foo") +} +fn tfoo() -> Box<(i32, [u8])> { + Box::new((42, *b"foo")) +} +fn afoo() -> Box<A<[u8]>> { + Box::new(A(*b"foo")) +} + +impl std::ops::Add<i32> for A<[u8]> { + type Output = (); + fn add(self, _rhs: i32) -> Self::Output {} +} + +fn main() { + udrop::<[u8]>(loop { + break *foo(); + }); + udrop::<[u8]>(if true { + *foo() + } else { + *foo() + }); + udrop::<[u8]>({*foo()}); + #[allow(unused_parens)] + udrop::<[u8]>((*foo())); + udrop::<[u8]>((*tfoo()).1); + *afoo() + 42; +} diff --git a/src/test/run-pass/unsized-locals/unsized-parameters.rs b/src/test/run-pass/unsized-locals/unsized-parameters.rs new file mode 100644 index 00000000000..0314fe1d686 --- /dev/null +++ b/src/test/run-pass/unsized-locals/unsized-parameters.rs @@ -0,0 +1,20 @@ +// 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)] + +pub fn f0(_f: dyn FnOnce()) {} +pub fn f1(_s: str) {} +pub fn f2((_x, _y): (i32, [i32])) {} + +fn main() { + let foo = "foo".to_string().into_boxed_str(); + f1(*foo); +} |
