1 // The regression test for #15031 to make sure destructuring trait
2 // reference work properly.
4 #![feature(box_patterns)]
6 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::new(1isize) as Box<dyn T>;
29 //~^ ERROR type `Box<dyn T>` cannot be dereferenced
32 let &&x = &1isize as &dyn T;
33 //~^ ERROR mismatched types
34 //~| expected trait object `dyn T`
35 //~| found reference `&_`
36 let &&&x = &(&1isize as &dyn T);
37 //~^ ERROR mismatched types
38 //~| expected trait object `dyn T`
39 //~| found reference `&_`
40 let box box x = Box::new(1isize) as Box<dyn T>;
41 //~^ ERROR mismatched types
42 //~| expected trait object `dyn T`
43 //~| found struct `Box<_>`