]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/unboxed-closure-sugar-equiv.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / test / compile-fail / unboxed-closure-sugar-equiv.rs
1 // Copyright 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 // Test that the unboxed closure sugar can be used with an arbitrary
12 // struct type and that it is equivalent to the same syntax using
13 // angle brackets. This test covers only simple types and in
14 // particular doesn't test bound regions.
15
16 #![feature(unboxed_closures)]
17 #![allow(dead_code)]
18
19 trait Foo<T> {
20 type Output;
21 fn dummy(&self, t: T, u: Self::Output);
22 }
23
24 trait Eq<X: ?Sized> { }
25 impl<X: ?Sized> Eq<X> for X { }
26 fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
27
28 fn test<'a,'b>() {
29 // No errors expected:
30 eq::< Foo<(),Output=()>, Foo() >();
31 eq::< Foo<(isize,),Output=()>, Foo(isize) >();
32 eq::< Foo<(isize,usize),Output=()>, Foo(isize,usize) >();
33 eq::< Foo<(isize,usize),Output=usize>, Foo(isize,usize) -> usize >();
34 eq::< Foo<(&'a isize,&'b usize),Output=usize>, Foo(&'a isize,&'b usize) -> usize >();
35
36 // Test that anonymous regions in `()` form are equivalent
37 // to fresh bound regions, and that we can intermingle
38 // named and anonymous as we choose:
39 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
40 for<'x,'y> Foo(&'x isize,&'y usize) -> usize >();
41 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
42 for<'x> Foo(&'x isize,&usize) -> usize >();
43 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
44 for<'y> Foo(&isize,&'y usize) -> usize >();
45 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
46 Foo(&isize,&usize) -> usize >();
47
48 // lifetime elision
49 eq::< for<'x> Foo<(&'x isize,), Output=&'x isize>,
50 Foo(&isize) -> &isize >();
51
52 // Errors expected:
53 eq::< Foo<(),Output=()>,
54 Foo(char) >();
55 //~^^ ERROR E0277
56 }
57
58 fn main() { }