1 // The regression test for #15031 to make sure destructuring trait
2 // reference work properly.
4 #![feature(box_patterns)]
5 #![feature(box_syntax)]
7 trait T { fn foo(&self) {} }
11 // For an expression of the form:
13 // let &...&x = &..&SomeTrait;
15 // Say we have n `&` at the left hand and m `&` right hand, then:
16 // if n < m, we are golden;
17 // if n == m, it's a derefing non-derefable type error;
18 // if n > m, it's a type mismatch error.
21 let &x = &(&1isize as &dyn T);
22 let &x = &&(&1isize as &dyn T);
23 let &&x = &&(&1isize as &dyn T);
26 let &x = &1isize as &dyn T; //~ ERROR type `&dyn T` cannot be dereferenced
27 let &&x = &(&1isize as &dyn T); //~ ERROR type `&dyn T` cannot be dereferenced
28 let box x = box 1isize as Box<dyn T>;
29 //~^ ERROR type `std::boxed::Box<dyn T>` cannot be dereferenced
32 let &&x = &1isize as &dyn T;
33 //~^ ERROR mismatched types
34 //~| expected type `dyn T`
36 //~| expected trait T, found reference
37 let &&&x = &(&1isize as &dyn T);
38 //~^ ERROR mismatched types
39 //~| expected type `dyn T`
41 //~| expected trait T, found reference
42 let box box x = box 1isize as Box<dyn T>;
43 //~^ ERROR mismatched types
44 //~| expected type `dyn T`
45 //~| found type `std::boxed::Box<_>`