From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../by-value-trait-objects-rust-call.rs | 55 +++++++++++++++++ .../by-value-trait-objects-rust-call2.rs | 69 ++++++++++++++++++++++ .../unsized-locals/by-value-trait-objects.rs | 49 +++++++++++++++ .../long-live-the-unsized-temporary.rs | 52 ++++++++++++++++ 4 files changed, 225 insertions(+) create mode 100644 src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs create mode 100644 src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs create mode 100644 src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs create mode 100644 src/test/run-pass-valgrind/unsized-locals/long-live-the-unsized-temporary.rs (limited to 'src/test/run-pass-valgrind/unsized-locals') diff --git a/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs b/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs new file mode 100644 index 000000000..7f365ce2b --- /dev/null +++ b/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call.rs @@ -0,0 +1,55 @@ +#![feature(unsized_locals)] +#![feature(unboxed_closures)] + +pub trait FnOnce { + 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); + +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>); + assert_eq!(x.call_once(()), format!("hello")); + let x = *(Box::new(B(42)) as Box>); + assert_eq!(x.call_once(()), format!("42")); + let x = *(Box::new(C(format!("jumping fox"))) as Box>); + assert_eq!(x.call_once(()), format!("jumping fox")); + let x = *(Box::new(D(Box::new(format!("lazy dog")))) as Box>); + assert_eq!(x.call_once(()), format!("lazy dog")); +} diff --git a/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs b/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs new file mode 100644 index 000000000..a78b897d1 --- /dev/null +++ b/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects-rust-call2.rs @@ -0,0 +1,69 @@ +#![feature(unsized_locals)] +#![feature(unboxed_closures)] + +pub trait FnOnce { + type Output; + extern "rust-call" fn call_once(self, args: Args) -> Self::Output; +} + +struct A; + +impl FnOnce<(String, Box)> for A { + type Output = String; + extern "rust-call" fn call_once(self, (s1, s2): (String, Box)) -> Self::Output { + assert_eq!(&s1 as &str, "s1"); + assert_eq!(&s2 as &str, "s2"); + format!("hello") + } +} + +struct B(i32); + +impl FnOnce<(String, Box)> for B { + type Output = String; + extern "rust-call" fn call_once(self, (s1, s2): (String, Box)) -> Self::Output { + assert_eq!(&s1 as &str, "s1"); + assert_eq!(&s2 as &str, "s2"); + format!("{}", self.0) + } +} + +struct C(String); + +impl FnOnce<(String, Box)> for C { + type Output = String; + extern "rust-call" fn call_once(self, (s1, s2): (String, Box)) -> Self::Output { + assert_eq!(&s1 as &str, "s1"); + assert_eq!(&s2 as &str, "s2"); + self.0 + } +} + +struct D(Box); + +impl FnOnce<(String, Box)> for D { + type Output = String; + extern "rust-call" fn call_once(self, (s1, s2): (String, Box)) -> 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), 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), 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), 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), Output = String>>); + assert_eq!(x.call_once((s1, s2)), format!("lazy dog")); +} diff --git a/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs b/src/test/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs new file mode 100644 index 000000000..3d67101e7 --- /dev/null +++ b/src/test/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); + +impl Foo for D { + fn foo(self) -> String { + *self.0 + } +} + + +fn main() { + let x = *(Box::new(A) as Box); + assert_eq!(x.foo(), format!("hello")); + let x = *(Box::new(B(42)) as Box); + assert_eq!(x.foo(), format!("42")); + let x = *(Box::new(C(format!("jumping fox"))) as Box); + assert_eq!(x.foo(), format!("jumping fox")); + let x = *(Box::new(D(Box::new(format!("lazy dog")))) as Box); + assert_eq!(x.foo(), format!("lazy dog")); +} 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 000000000..a7b905261 --- /dev/null +++ b/src/test/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 { + 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); + } +} -- cgit v1.2.3