]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/unboxed-closure-sugar-equiv.rs
Add a doctest for the std::string::as_string method.
[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 trait Foo<T,U> {
20     fn dummy(&self, t: T, u: U);
21 }
22
23 trait Eq<Sized? X> for Sized? { }
24 impl<Sized? X> Eq<X> for X { }
25 fn eq<Sized? A,Sized? B:Eq<A>>() { }
26
27 fn test<'a,'b>() {
28     // No errors expected:
29     eq::< Foo<(),()>,                   Foo()                         >();
30     eq::< Foo<(int,),()>,               Foo(int)                      >();
31     eq::< Foo<(int,uint),()>,           Foo(int,uint)                 >();
32     eq::< Foo<(int,uint),uint>,         Foo(int,uint) -> uint         >();
33     eq::< Foo<(&'a int,&'b uint),uint>, Foo(&'a int,&'b uint) -> uint >();
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<'a,'b> Foo<(&'a int,&'b uint),uint>,
39           for<'a,'b> Foo(&'a int,&'b uint) -> uint            >();
40     eq::< for<'a,'b> Foo<(&'a int,&'b uint),uint>,
41           for<'a> Foo(&'a int,&uint) -> uint                  >();
42     eq::< for<'a,'b> Foo<(&'a int,&'b uint),uint>,
43           for<'b> Foo(&int,&'b uint) -> uint                  >();
44     eq::< for<'a,'b> Foo<(&'a int,&'b uint),uint>,
45           Foo(&int,&uint) -> uint                             >();
46
47     // FIXME(#18992) Test lifetime elision in `()` form:
48     // eq::< for<'a,'b> Foo<(&'a int,), &'a int>,
49     //      Foo(&int) -> &int                                   >();
50
51     // Errors expected:
52     eq::< Foo<(),()>,                   Foo(char)                     >();
53     //~^ ERROR not implemented
54 }
55
56 fn main() { }