2014-11-03 20:52:52 -06:00
|
|
|
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// 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 15:04:04 -06:00
|
|
|
#![feature(unboxed_closures)]
|
2014-11-03 20:52:52 -06:00
|
|
|
#![allow(dead_code)]
|
|
|
|
|
2015-01-12 09:27:25 -06:00
|
|
|
trait Foo<T> {
|
|
|
|
type Output;
|
|
|
|
fn dummy(&self, t: T, u: Self::Output);
|
2014-11-03 20:52:52 -06:00
|
|
|
}
|
|
|
|
|
2015-03-31 18:58:01 -05:00
|
|
|
trait Eq<X: ?Sized> { }
|
2015-01-05 15:16:49 -06:00
|
|
|
impl<X: ?Sized> Eq<X> for X { }
|
|
|
|
fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }
|
2014-11-03 20:52:52 -06:00
|
|
|
|
|
|
|
fn test<'a,'b>() {
|
|
|
|
// No errors expected:
|
2015-01-12 09:27:25 -06:00
|
|
|
eq::< Foo<(),Output=()>, Foo() >();
|
|
|
|
eq::< Foo<(isize,),Output=()>, Foo(isize) >();
|
|
|
|
eq::< Foo<(isize,usize),Output=()>, Foo(isize,usize) >();
|
|
|
|
eq::< Foo<(isize,usize),Output=usize>, Foo(isize,usize) -> usize >();
|
|
|
|
eq::< Foo<(&'a isize,&'b usize),Output=usize>, Foo(&'a isize,&'b usize) -> usize >();
|
2014-11-03 20:52:52 -06:00
|
|
|
|
2014-11-15 18:10:22 -06:00
|
|
|
// Test that anonymous regions in `()` form are equivalent
|
|
|
|
// to fresh bound regions, and that we can intermingle
|
|
|
|
// named and anonymous as we choose:
|
2015-01-12 09:27:25 -06:00
|
|
|
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
2015-01-08 05:02:42 -06:00
|
|
|
for<'x,'y> Foo(&'x isize,&'y usize) -> usize >();
|
2015-01-12 09:27:25 -06:00
|
|
|
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
2015-01-08 05:02:42 -06:00
|
|
|
for<'x> Foo(&'x isize,&usize) -> usize >();
|
2015-01-12 09:27:25 -06:00
|
|
|
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
2015-01-08 05:02:42 -06:00
|
|
|
for<'y> Foo(&isize,&'y usize) -> usize >();
|
2015-01-12 09:27:25 -06:00
|
|
|
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
|
2015-01-08 05:02:42 -06:00
|
|
|
Foo(&isize,&usize) -> usize >();
|
2014-11-15 18:10:22 -06:00
|
|
|
|
2014-12-05 21:01:07 -06:00
|
|
|
// lifetime elision
|
2015-01-12 09:27:25 -06:00
|
|
|
eq::< for<'x> Foo<(&'x isize,), Output=&'x isize>,
|
2015-01-08 04:54:35 -06:00
|
|
|
Foo(&isize) -> &isize >();
|
2014-11-15 18:10:22 -06:00
|
|
|
|
2014-11-03 20:52:52 -06:00
|
|
|
// Errors expected:
|
2015-01-12 09:27:25 -06:00
|
|
|
eq::< Foo<(),Output=()>,
|
|
|
|
Foo(char) >();
|
2016-03-29 12:12:31 -05:00
|
|
|
//~^^ ERROR E0277
|
2014-11-03 20:52:52 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() { }
|