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.
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.
11 // The regression test for #15031 to make sure destructuring trait
12 // reference work properly.
14 #![feature(box_patterns)]
15 #![feature(box_syntax)]
17 trait T { fn foo(&self) {} }
21 // For an expression of the form:
23 // let &...&x = &..&SomeTrait;
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.
31 let &x = &(&1isize as &T);
32 let &x = &&(&1isize as &T);
33 let &&x = &&(&1isize as &T);
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
41 let &&x = &1isize as &T;
42 //~^ ERROR mismatched types
43 //~| expected type `T`
45 //~| expected trait T, found reference
46 let &&&x = &(&1isize as &T);
47 //~^ ERROR mismatched types
48 //~| expected type `T`
50 //~| expected trait T, found reference
51 let box box x = box 1isize as Box<T>;
52 //~^ ERROR mismatched types
53 //~| expected type `T`
54 //~| found type `std::boxed::Box<_>`