]> git.lizzy.rs Git - rust.git/blob - src/test/ui/destructure-trait-ref.rs
Rollup merge of #53317 - estebank:abolish-ice, r=oli-obk
[rust.git] / src / test / ui / destructure-trait-ref.rs
1 // Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // The regression test for #15031 to make sure destructuring trait
12 // reference work properly.
13
14 #![feature(box_patterns)]
15 #![feature(box_syntax)]
16
17 trait T { fn foo(&self) {} }
18 impl T for isize {}
19
20 fn main() {
21     // For an expression of the form:
22     //
23     //      let &...&x = &..&SomeTrait;
24     //
25     // Say we have n `&` at the left hand and m `&` right hand, then:
26     // if n < m, we are golden;
27     // if n == m, it's a derefing non-derefable type error;
28     // if n > m, it's a type mismatch error.
29
30     // n < m
31     let &x = &(&1isize as &T);
32     let &x = &&(&1isize as &T);
33     let &&x = &&(&1isize as &T);
34
35     // n == m
36     let &x = &1isize as &T;      //~ ERROR type `&dyn T` cannot be dereferenced
37     let &&x = &(&1isize as &T);  //~ ERROR type `&dyn T` cannot be dereferenced
38     let box x = box 1isize as Box<T>; //~ ERROR type `std::boxed::Box<dyn T>` cannot be dereferenced
39
40     // n > m
41     let &&x = &1isize as &T;
42     //~^ ERROR mismatched types
43     //~| expected type `dyn T`
44     //~| found type `&_`
45     //~| expected trait T, found reference
46     let &&&x = &(&1isize as &T);
47     //~^ ERROR mismatched types
48     //~| expected type `dyn T`
49     //~| found type `&_`
50     //~| expected trait T, found reference
51     let box box x = box 1isize as Box<T>;
52     //~^ ERROR mismatched types
53     //~| expected type `dyn T`
54     //~| found type `std::boxed::Box<_>`
55 }