]> git.lizzy.rs Git - rust.git/blob - tests/ui/unsized-locals/autoderef.rs
Rollup merge of #103236 - tspiteri:redoc-int-adc-sbb, r=m-ou-se
[rust.git] / tests / ui / unsized-locals / autoderef.rs
1 // run-pass
2
3 #![allow(incomplete_features)]
4 #![feature(unsized_locals, unsized_fn_params)]
5
6 pub trait Foo {
7     fn foo(self) -> String;
8 }
9
10 impl Foo for [char] {
11     fn foo(self) -> String {
12         self.iter().collect()
13     }
14 }
15
16 impl Foo for str {
17     fn foo(self) -> String {
18         self.to_owned()
19     }
20 }
21
22 impl Foo for dyn FnMut() -> String {
23     fn foo(mut self) -> String {
24         self()
25     }
26 }
27
28 fn main() {
29     let x = *(Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>);
30     assert_eq!(&x.foo() as &str, "hello");
31
32     let x = Box::new(['h', 'e', 'l', 'l', 'o']) as Box<[char]>;
33     assert_eq!(&x.foo() as &str, "hello");
34
35     let x = "hello".to_owned().into_boxed_str();
36     assert_eq!(&x.foo() as &str, "hello");
37
38     let x = *("hello".to_owned().into_boxed_str());
39     assert_eq!(&x.foo() as &str, "hello");
40
41     let x = "hello".to_owned().into_boxed_str();
42     assert_eq!(&x.foo() as &str, "hello");
43
44     let x = *(Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>);
45     assert_eq!(&x.foo() as &str, "hello");
46
47     let x = Box::new(|| "hello".to_owned()) as Box<dyn FnMut() -> String>;
48     assert_eq!(&x.foo() as &str, "hello");
49 }