summaryrefslogtreecommitdiffstats
path: root/tests/run-pass-valgrind/unsized-locals
diff options
context:
space:
mode:
Diffstat (limited to 'tests/run-pass-valgrind/unsized-locals')
-rw-r--r--tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs56
-rw-r--r--tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs70
-rw-r--r--tests/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs49
-rw-r--r--tests/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs52
4 files changed, 227 insertions, 0 deletions
diff --git a/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs b/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs
new file mode 100644
index 000000000..ece4dea9a
--- /dev/null
+++ b/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs
@@ -0,0 +1,56 @@
+#![feature(unsized_locals)]
+#![feature(unboxed_closures)]
+#![feature(tuple_trait)]
+
+pub trait FnOnce<Args: std::marker::Tuple> {
+ type Output;
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+struct A;
+
+impl FnOnce<()> for A {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (): ()) -> Self::Output {
+ format!("hello")
+ }
+}
+
+struct B(i32);
+
+impl FnOnce<()> for B {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (): ()) -> Self::Output {
+ format!("{}", self.0)
+ }
+}
+
+struct C(String);
+
+impl FnOnce<()> for C {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (): ()) -> Self::Output {
+ self.0
+ }
+}
+
+struct D(Box<String>);
+
+impl FnOnce<()> for D {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (): ()) -> Self::Output {
+ *self.0
+ }
+}
+
+
+fn main() {
+ let x = *(Box::new(A) as Box<dyn FnOnce<(), Output = String>>);
+ assert_eq!(x.call_once(()), format!("hello"));
+ let x = *(Box::new(B(42)) as Box<dyn FnOnce<(), Output = String>>);
+ assert_eq!(x.call_once(()), format!("42"));
+ let x = *(Box::new(C(format!("jumping fox"))) as Box<dyn FnOnce<(), Output = String>>);
+ assert_eq!(x.call_once(()), format!("jumping fox"));
+ let x = *(Box::new(D(Box::new(format!("lazy dog")))) as Box<dyn FnOnce<(), Output = String>>);
+ assert_eq!(x.call_once(()), format!("lazy dog"));
+}
diff --git a/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs b/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs
new file mode 100644
index 000000000..94df2b0b8
--- /dev/null
+++ b/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs
@@ -0,0 +1,70 @@
+#![feature(unsized_locals)]
+#![feature(unboxed_closures)]
+#![feature(tuple_trait)]
+
+pub trait FnOnce<Args: std::marker::Tuple> {
+ type Output;
+ extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
+}
+
+struct A;
+
+impl FnOnce<(String, Box<str>)> for A {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
+ assert_eq!(&s1 as &str, "s1");
+ assert_eq!(&s2 as &str, "s2");
+ format!("hello")
+ }
+}
+
+struct B(i32);
+
+impl FnOnce<(String, Box<str>)> for B {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
+ assert_eq!(&s1 as &str, "s1");
+ assert_eq!(&s2 as &str, "s2");
+ format!("{}", self.0)
+ }
+}
+
+struct C(String);
+
+impl FnOnce<(String, Box<str>)> for C {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
+ assert_eq!(&s1 as &str, "s1");
+ assert_eq!(&s2 as &str, "s2");
+ self.0
+ }
+}
+
+struct D(Box<String>);
+
+impl FnOnce<(String, Box<str>)> for D {
+ type Output = String;
+ extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
+ assert_eq!(&s1 as &str, "s1");
+ assert_eq!(&s2 as &str, "s2");
+ *self.0
+ }
+}
+
+
+fn main() {
+ let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
+ let x = *(Box::new(A) as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
+ assert_eq!(x.call_once((s1, s2)), format!("hello"));
+ let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
+ let x = *(Box::new(B(42)) as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
+ assert_eq!(x.call_once((s1, s2)), format!("42"));
+ let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
+ let x = *(Box::new(C(format!("jumping fox")))
+ as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
+ assert_eq!(x.call_once((s1, s2)), format!("jumping fox"));
+ let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
+ let x = *(Box::new(D(Box::new(format!("lazy dog"))))
+ as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
+ assert_eq!(x.call_once((s1, s2)), format!("lazy dog"));
+}
diff --git a/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs b/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs
new file mode 100644
index 000000000..3d67101e7
--- /dev/null
+++ b/tests/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs
@@ -0,0 +1,49 @@
+#![feature(unsized_locals)]
+
+pub trait Foo {
+ fn foo(self) -> String;
+}
+
+struct A;
+
+impl Foo for A {
+ fn foo(self) -> String {
+ format!("hello")
+ }
+}
+
+struct B(i32);
+
+impl Foo for B {
+ fn foo(self) -> String {
+ format!("{}", self.0)
+ }
+}
+
+struct C(String);
+
+impl Foo for C {
+ fn foo(self) -> String {
+ self.0
+ }
+}
+
+struct D(Box<String>);
+
+impl Foo for D {
+ fn foo(self) -> String {
+ *self.0
+ }
+}
+
+
+fn main() {
+ let x = *(Box::new(A) as Box<dyn Foo>);
+ assert_eq!(x.foo(), format!("hello"));
+ let x = *(Box::new(B(42)) as Box<dyn Foo>);
+ assert_eq!(x.foo(), format!("42"));
+ let x = *(Box::new(C(format!("jumping fox"))) as Box<dyn Foo>);
+ assert_eq!(x.foo(), format!("jumping fox"));
+ let x = *(Box::new(D(Box::new(format!("lazy dog")))) as Box<dyn Foo>);
+ assert_eq!(x.foo(), format!("lazy dog"));
+}
diff --git a/tests/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs b/tests/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs
new file mode 100644
index 000000000..a7b905261
--- /dev/null
+++ b/tests/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs
@@ -0,0 +1,52 @@
+#![allow(incomplete_features)]
+#![feature(unsized_locals, unsized_fn_params)]
+
+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);
+ }
+}