]> git.proxmox.com Git - rustc.git/blob - src/test/compile-fail/unboxed-closure-sugar-equiv.rs
Imported Upstream version 1.0.0~0alpha
[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,U> {
20 fn dummy(&self, t: T, u: U);
21 }
22
23 trait Eq<X: ?Sized> { }
24 impl<X: ?Sized> Eq<X> for X { }
25 fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
26
27 fn test<'a,'b>() {
28 // No errors expected:
29 eq::< Foo<(),()>, Foo() >();
30 eq::< Foo<(isize,),()>, Foo(isize) >();
31 eq::< Foo<(isize,usize),()>, Foo(isize,usize) >();
32 eq::< Foo<(isize,usize),usize>, Foo(isize,usize) -> usize >();
33 eq::< Foo<(&'a isize,&'b usize),usize>, Foo(&'a isize,&'b usize) -> usize >();
34
35 // Test that anonymous regions in `()` form are equivalent
36 // to fresh bound regions, and that we can intermingle
37 // named and anonymous as we choose:
38 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
39 for<'x,'y> Foo(&'x isize,&'y usize) -> usize >();
40 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
41 for<'x> Foo(&'x isize,&usize) -> usize >();
42 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
43 for<'y> Foo(&isize,&'y usize) -> usize >();
44 eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
45 Foo(&isize,&usize) -> usize >();
46
47 // lifetime elision
48 eq::< for<'x> Foo<(&'x isize,), &'x isize>,
49 Foo(&isize) -> &isize >();
50
51 // Errors expected:
52 eq::< Foo<(),()>, Foo(char) >();
53 //~^ ERROR not implemented
54 }
55
56 fn main() { }