2014-11-04 02:52:52 +00:00
|
|
|
// Test that the unboxed closure sugar can be used with an arbitrary
|
|
|
|
// struct type and that it is equivalent to the same syntax using
|
|
|
|
// angle brackets. This test covers only simple types and in
|
|
|
|
// particular doesn't test bound regions.
|
|
|
|
|
2014-11-15 21:04:04 +00:00
|
|
|
#![feature(unboxed_closures)]
|
2014-11-04 02:52:52 +00:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2015-01-12 15:27:25 +00:00
|
|
|
trait Foo<T> {
|
|
|
|
type Output;
|
|
|
|
fn dummy(&self, t: T, u: Self::Output);
|
2014-11-04 02:52:52 +00:00
|
|
|
}
|
|
|
|
|
2015-03-31 23:58:01 +00:00
|
|
|
trait Eq<X: ?Sized> { }
|
2015-01-05 21:16:49 +00:00
|
|
|
impl<X: ?Sized> Eq<X> for X { }
|
|
|
|
fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
|
2014-11-04 02:52:52 +00:00
|
|
|
|
|
|
|
fn test<'a,'b>() {
|
|
|
|
// No errors expected:
|
2019-05-28 18:46:13 +00:00
|
|
|
eq::< dyn Foo<(),Output=()>, dyn Foo() >();
|
|
|
|
eq::< dyn Foo<(isize,),Output=()>, dyn Foo(isize) >();
|
|
|
|
eq::< dyn Foo<(isize,usize),Output=()>, dyn Foo(isize,usize) >();
|
|
|
|
eq::< dyn Foo<(isize,usize),Output=usize>, dyn Foo(isize,usize) -> usize >();
|
|
|
|
eq::< dyn Foo<(&'a isize,&'b usize),Output=usize>, dyn Foo(&'a isize,&'b usize) -> usize >();
|
2014-11-04 02:52:52 +00:00
|
|
|
|
2014-11-16 00:10:22 +00:00
|
|
|
// Test that anonymous regions in `()` form are equivalent
|
|
|
|
// to fresh bound regions, and that we can intermingle
|
|
|
|
// named and anonymous as we choose:
|
2019-05-28 18:46:13 +00:00
|
|
|
eq::< dyn for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
|
|
|
dyn for<'x,'y> Foo(&'x isize,&'y usize) -> usize >();
|
|
|
|
eq::< dyn for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
|
|
|
dyn for<'x> Foo(&'x isize,&usize) -> usize >();
|
|
|
|
eq::< dyn for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
|
|
|
dyn for<'y> Foo(&isize,&'y usize) -> usize >();
|
|
|
|
eq::< dyn for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
|
|
|
dyn Foo(&isize,&usize) -> usize >();
|
2014-11-16 00:10:22 +00:00
|
|
|
|
2014-12-06 03:01:07 +00:00
|
|
|
// lifetime elision
|
2019-05-28 18:46:13 +00:00
|
|
|
eq::< dyn for<'x> Foo<(&'x isize,), Output=&'x isize>,
|
|
|
|
dyn Foo(&isize) -> &isize >();
|
2014-11-16 00:10:22 +00:00
|
|
|
|
2014-11-04 02:52:52 +00:00
|
|
|
// Errors expected:
|
2019-05-28 18:46:13 +00:00
|
|
|
eq::< dyn Foo<(),Output=()>,
|
|
|
|
dyn Foo(char) >();
|
2022-07-16 22:34:22 +00:00
|
|
|
//~^ ERROR E0277
|
2014-11-04 02:52:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|