]> git.proxmox.com Git - rustc.git/blame - 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
CommitLineData
1a4d82fc
JJ
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
85aaf69f 14#![feature(box_patterns)]
1a4d82fc
JJ
15#![feature(box_syntax)]
16
85aaf69f 17trait T { fn foo(&self) {} }
1a4d82fc
JJ
18impl T for isize {}
19
20fn 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
62682a34
SL
31 let &x = &(&1isize as &T);
32 let &x = &&(&1isize as &T);
33 let &&x = &&(&1isize as &T);
1a4d82fc
JJ
34
35 // n == m
62682a34
SL
36 let &x = &1isize as &T; //~ ERROR type `&T` cannot be dereferenced
37 let &&x = &(&1isize as &T); //~ ERROR type `&T` cannot be dereferenced
54a0048b 38 let box x = box 1isize as Box<T>; //~ ERROR `T: std::marker::Sized` is not satisfied
1a4d82fc
JJ
39
40 // n > m
62682a34 41 let &&x = &1isize as &T;
85aaf69f
SL
42 //~^ ERROR mismatched types
43 //~| expected `T`
44 //~| found `&_`
45 //~| expected trait T
46 //~| found &-ptr
62682a34 47 let &&&x = &(&1isize as &T);
85aaf69f
SL
48 //~^ ERROR mismatched types
49 //~| expected `T`
50 //~| found `&_`
51 //~| expected trait T
52 //~| found &-ptr
62682a34 53 let box box x = box 1isize as Box<T>;
85aaf69f
SL
54 //~^ ERROR mismatched types
55 //~| expected `T`
56 //~| found `Box<_>`
57 //~| expected trait T
58 //~| found box
1a4d82fc 59}