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