7 fn box_method(self: Box<Self>);
10 impl Trait for Struct {
12 assert_eq!(self.0, 42);
15 fn box_method(self: Box<Self>) {
16 assert_eq!(self.0, 7);
20 struct Foo<T: ?Sized>(T);
22 let y: &dyn Trait = &Struct(42);
25 let x: Foo<Struct> = Foo(Struct(42));
26 let y: &Foo<dyn Trait> = &x;
29 let y: Box<dyn Trait> = Box::new(Struct(42));
35 let y: Box<dyn Trait> = Box::new(Struct(7));
40 struct DroppableStruct;
42 static mut DROPPED: bool = false;
44 impl Drop for DroppableStruct {
55 impl MyTrait for Box<DroppableStruct> {}
58 w: Box<dyn MyTrait + 'static>,
62 fn new(w: Box<dyn MyTrait + 'static>) -> Whatever {
68 let f = Box::new(DroppableStruct);
69 let a = Whatever::new(Box::new(f) as Box<dyn MyTrait>);
72 assert!(unsafe { DROPPED });
75 // Disabled for now: unsized locals are not supported,
76 // their current MIR encoding is just not great.
80 fn foo(self) -> String;
86 fn foo(self) -> String {
91 let x = *(Box::new(A) as Box<dyn Foo>);
92 assert_eq!(x.foo(), format!("hello"));
94 // I'm not sure whether we want this to work
95 let x = Box::new(A) as Box<dyn Foo>;
96 assert_eq!(x.foo(), format!("hello"));
98 fn unsized_dyn_autoderef() {
100 fn foo(self) -> String;
103 impl Foo for [char] {
104 fn foo(self) -> String {
105 self.iter().collect()
110 fn foo(self) -> String {
115 impl Foo for dyn FnMut() -> String {
116 fn foo(mut self) -> String {
121 let x = *(Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>);
122 assert_eq!(&x.foo() as &str, "hello");
124 let x = Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>;
125 assert_eq!(&x.foo() as &str, "hello");
127 let x = "hello".to_owned().into_boxed_str();
128 assert_eq!(&x.foo() as &str, "hello");
130 let x = *("hello".to_owned().into_boxed_str());
131 assert_eq!(&x.foo() as &str, "hello");
133 let x = "hello".to_owned().into_boxed_str();
134 assert_eq!(&x.foo() as &str, "hello");
136 let x = *(Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>);
137 assert_eq!(&x.foo() as &str, "hello");
139 let x = Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>;
140 assert_eq!(&x.foo() as &str, "hello");