]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/destructure-trait-ref.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / 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 `&T` cannot be dereferenced
37 let &&x = &(&1isize as &T); //~ ERROR type `&T` cannot be dereferenced
38 let box x = box 1isize as Box<T>; //~ ERROR `T: std::marker::Sized` is not satisfied
39
40 // n > m
41 let &&x = &1isize as &T;
42 //~^ ERROR mismatched types
43 //~| expected `T`
44 //~| found `&_`
45 //~| expected trait T
46 //~| found &-ptr
47 let &&&x = &(&1isize as &T);
48 //~^ ERROR mismatched types
49 //~| expected `T`
50 //~| found `&_`
51 //~| expected trait T
52 //~| found &-ptr
53 let box box x = box 1isize as Box<T>;
54 //~^ ERROR mismatched types
55 //~| expected `T`
56 //~| found `Box<_>`
57 //~| expected trait T
58 //~| found box
59 }