]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/unboxed-closure-sugar-equiv.rs
Auto merge of #22541 - Manishearth:rollup, r=Gankro
[rust.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 use std::marker::PhantomFn;
20
21 trait Foo<T> {
22     type Output;
23     fn dummy(&self, t: T, u: Self::Output);
24 }
25
26 trait Eq<X: ?Sized> : PhantomFn<(Self,X)> { }
27 impl<X: ?Sized> Eq<X> for X { }
28 fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
29
30 fn test<'a,'b>() {
31     // No errors expected:
32     eq::< Foo<(),Output=()>,                       Foo()                         >();
33     eq::< Foo<(isize,),Output=()>,                 Foo(isize)                      >();
34     eq::< Foo<(isize,usize),Output=()>,            Foo(isize,usize)                 >();
35     eq::< Foo<(isize,usize),Output=usize>,         Foo(isize,usize) -> usize         >();
36     eq::< Foo<(&'a isize,&'b usize),Output=usize>, Foo(&'a isize,&'b usize) -> usize >();
37
38     // Test that anonymous regions in `()` form are equivalent
39     // to fresh bound regions, and that we can intermingle
40     // named and anonymous as we choose:
41     eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
42           for<'x,'y> Foo(&'x isize,&'y usize) -> usize            >();
43     eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
44           for<'x> Foo(&'x isize,&usize) -> usize                  >();
45     eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
46           for<'y> Foo(&isize,&'y usize) -> usize                  >();
47     eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
48           Foo(&isize,&usize) -> usize                             >();
49
50     // lifetime elision
51     eq::< for<'x> Foo<(&'x isize,), Output=&'x isize>,
52           Foo(&isize) -> &isize                                   >();
53
54     // Errors expected:
55     eq::< Foo<(),Output=()>,
56           Foo(char)                                               >();
57     //~^^ ERROR not implemented
58 }
59
60 fn main() { }