]> git.proxmox.com Git - rustc.git/blame - src/test/ui/destructure-trait-ref.rs
New upstream version 1.41.1+dfsg1
[rustc.git] / src / test / ui / destructure-trait-ref.rs
CommitLineData
1a4d82fc
JJ
1// The regression test for #15031 to make sure destructuring trait
2// reference work properly.
3
85aaf69f 4#![feature(box_patterns)]
1a4d82fc
JJ
5#![feature(box_syntax)]
6
85aaf69f 7trait T { fn foo(&self) {} }
1a4d82fc
JJ
8impl T for isize {}
9
10fn 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
dc9dc135
XL
21 let &x = &(&1isize as &dyn T);
22 let &x = &&(&1isize as &dyn T);
23 let &&x = &&(&1isize as &dyn T);
1a4d82fc
JJ
24
25 // n == m
dc9dc135
XL
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
1a4d82fc
JJ
30
31 // n > m
dc9dc135 32 let &&x = &1isize as &dyn T;
85aaf69f 33 //~^ ERROR mismatched types
60c5eb7d
XL
34 //~| expected trait object `dyn T`
35 //~| found reference `&_`
36 //~| expected trait `T`, found reference
dc9dc135 37 let &&&x = &(&1isize as &dyn T);
85aaf69f 38 //~^ ERROR mismatched types
60c5eb7d
XL
39 //~| expected trait object `dyn T`
40 //~| found reference `&_`
41 //~| expected trait `T`, found reference
dc9dc135 42 let box box x = box 1isize as Box<dyn T>;
85aaf69f 43 //~^ ERROR mismatched types
60c5eb7d
XL
44 //~| expected trait object `dyn T`
45 //~| found struct `std::boxed::Box<_>`
1a4d82fc 46}