]> git.lizzy.rs Git - rust.git/blob - src/test/ui/destructure-trait-ref.rs
Rollup merge of #57132 - daxpedda:master, r=steveklabnik
[rust.git] / src / test / ui / destructure-trait-ref.rs
1 // The regression test for #15031 to make sure destructuring trait
2 // reference work properly.
3
4 #![feature(box_patterns)]
5 #![feature(box_syntax)]
6
7 trait T { fn foo(&self) {} }
8 impl T for isize {}
9
10 fn main() {
11     // For an expression of the form:
12     //
13     //      let &...&x = &..&SomeTrait;
14     //
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.
19
20     // n < m
21     let &x = &(&1isize as &T);
22     let &x = &&(&1isize as &T);
23     let &&x = &&(&1isize as &T);
24
25     // n == m
26     let &x = &1isize as &T;      //~ ERROR type `&dyn T` cannot be dereferenced
27     let &&x = &(&1isize as &T);  //~ ERROR type `&dyn T` cannot be dereferenced
28     let box x = box 1isize as Box<T>; //~ ERROR type `std::boxed::Box<dyn T>` cannot be dereferenced
29
30     // n > m
31     let &&x = &1isize as &T;
32     //~^ ERROR mismatched types
33     //~| expected type `dyn T`
34     //~| found type `&_`
35     //~| expected trait T, found reference
36     let &&&x = &(&1isize as &T);
37     //~^ ERROR mismatched types
38     //~| expected type `dyn T`
39     //~| found type `&_`
40     //~| expected trait T, found reference
41     let box box x = box 1isize as Box<T>;
42     //~^ ERROR mismatched types
43     //~| expected type `dyn T`
44     //~| found type `std::boxed::Box<_>`
45 }