1 #![feature(unsized_locals)]
2 #![feature(unboxed_closures)]
4 pub trait FnOnce<Args> {
6 extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
11 impl FnOnce<(String, Box<str>)> for A {
13 extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
14 assert_eq!(&s1 as &str, "s1");
15 assert_eq!(&s2 as &str, "s2");
22 impl FnOnce<(String, Box<str>)> for B {
24 extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
25 assert_eq!(&s1 as &str, "s1");
26 assert_eq!(&s2 as &str, "s2");
33 impl FnOnce<(String, Box<str>)> for C {
35 extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
36 assert_eq!(&s1 as &str, "s1");
37 assert_eq!(&s2 as &str, "s2");
42 struct D(Box<String>);
44 impl FnOnce<(String, Box<str>)> for D {
46 extern "rust-call" fn call_once(self, (s1, s2): (String, Box<str>)) -> Self::Output {
47 assert_eq!(&s1 as &str, "s1");
48 assert_eq!(&s2 as &str, "s2");
55 let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
56 let x = *(Box::new(A) as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
57 assert_eq!(x.call_once((s1, s2)), format!("hello"));
58 let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
59 let x = *(Box::new(B(42)) as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
60 assert_eq!(x.call_once((s1, s2)), format!("42"));
61 let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
62 let x = *(Box::new(C(format!("jumping fox")))
63 as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
64 assert_eq!(x.call_once((s1, s2)), format!("jumping fox"));
65 let (s1, s2) = (format!("s1"), format!("s2").into_boxed_str());
66 let x = *(Box::new(D(Box::new(format!("lazy dog"))))
67 as Box<dyn FnOnce<(String, Box<str>), Output = String>>);
68 assert_eq!(x.call_once((s1, s2)), format!("lazy dog"));