]> git.lizzy.rs Git - rust.git/blob - tests/run-pass-valgrind/unsized-locals/by-value-trait-objects.rs
Rollup merge of #103702 - WaffleLapkin:lift-sized-bounds-from-pointer-methods-where...
[rust.git] / tests / run-pass-valgrind / unsized-locals / by-value-trait-objects.rs
1 #![feature(unsized_locals)]
2
3 pub trait Foo {
4     fn foo(self) -> String;
5 }
6
7 struct A;
8
9 impl Foo for A {
10     fn foo(self) -> String {
11         format!("hello")
12     }
13 }
14
15 struct B(i32);
16
17 impl Foo for B {
18     fn foo(self) -> String {
19         format!("{}", self.0)
20     }
21 }
22
23 struct C(String);
24
25 impl Foo for C {
26     fn foo(self) -> String {
27         self.0
28     }
29 }
30
31 struct D(Box<String>);
32
33 impl Foo for D {
34     fn foo(self) -> String {
35         *self.0
36     }
37 }
38
39
40 fn main() {
41     let x = *(Box::new(A) as Box<dyn Foo>);
42     assert_eq!(x.foo(), format!("hello"));
43     let x = *(Box::new(B(42)) as Box<dyn Foo>);
44     assert_eq!(x.foo(), format!("42"));
45     let x = *(Box::new(C(format!("jumping fox"))) as Box<dyn Foo>);
46     assert_eq!(x.foo(), format!("jumping fox"));
47     let x = *(Box::new(D(Box::new(format!("lazy dog")))) as Box<dyn Foo>);
48     assert_eq!(x.foo(), format!("lazy dog"));
49 }