Skip to content

Commit

Permalink
Update test files; mostly the problem is that they were using the
Browse files Browse the repository at this point in the history
explicit form `Fn<A,B>` and now should use `Fn(A) -> B` or
`Fn<A,Output=B>`, but in some cases we get duplicate error
reports. This is mildly annoying and arises because of the main error
and another error from the projection. Might be worth squashing those,
but seems like a separate problem.
  • Loading branch information
nikomatsakis committed Jan 28, 2015
1 parent ac94ae5 commit 09783d1
Show file tree
Hide file tree
Showing 43 changed files with 201 additions and 126 deletions.
12 changes: 9 additions & 3 deletions src/test/compile-fail/borrowck-overloaded-call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ struct SFn {
y: isize,
}

impl Fn<(isize,),isize> for SFn {
impl Fn<(isize,)> for SFn {
type Output = isize;

extern "rust-call" fn call(&self, (z,): (isize,)) -> isize {
self.x * self.y * z
}
Expand All @@ -28,7 +30,9 @@ struct SFnMut {
y: isize,
}

impl FnMut<(isize,),isize> for SFnMut {
impl FnMut<(isize,)> for SFnMut {
type Output = isize;

extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize {
self.x * self.y * z
}
Expand All @@ -38,7 +42,9 @@ struct SFnOnce {
x: String,
}

impl FnOnce<(String,),usize> for SFnOnce {
impl FnOnce<(String,)> for SFnOnce {
type Output = usize;

extern "rust-call" fn call_once(self, (z,): (String,)) -> usize {
self.x.len() + z.len()
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/extern-wrong-value-type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,7 @@ fn is_fn<F>(_: F) where F: Fn() {}
fn main() {
// extern functions are extern "C" fn
let _x: extern "C" fn() = f; // OK
is_fn(f); //~ ERROR the trait `core::ops::Fn()` is not implemented for the type `extern "C" fn()
is_fn(f);
//~^ ERROR the trait `core::ops::Fn<()>` is not implemented for the type `extern "C" fn()
//~| ERROR the trait `core::ops::Fn<()>` is not implemented for the type `extern "C" fn()
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,38 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Test that manual impls of the `Fn` traits are not possible without
// a feature gate. In fact, the specialized check for these cases
// never triggers (yet), because they encounter other problems around
// angle bracket vs parentheses notation.

#![allow(dead_code)]

struct Foo;
impl Fn() for Foo { //~ ERROR manual implementations of `Fn` are experimental
impl Fn<()> for Foo {
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family of traits
type Output = ();

extern "rust-call" fn call(&self, args: ()) -> () {}
}
struct Foo1;
impl Fn() for Foo1 {
//~^ ERROR associated type bindings are not allowed here

extern "rust-call" fn call(&self, args: ()) -> () {}
}
struct Bar;
impl FnMut() for Bar { //~ ERROR manual implementations of `FnMut` are experimental
impl FnMut<()> for Bar {
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family of traits
type Output = ();

extern "rust-call" fn call_mut(&self, args: ()) -> () {}
}
struct Baz;
impl FnOnce() for Baz { //~ ERROR manual implementations of `FnOnce` are experimental
impl FnOnce<()> for Baz {
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family of traits
type Output = ();

extern "rust-call" fn call_once(&self, args: ()) -> () {}
}

Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/fn-trait-formatting.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,7 @@ fn main() {
//~| expected ()
//~| found box

needs_fn(1is); //~ ERROR `core::ops::Fn(isize) -> isize`
needs_fn(1is);
//~^ ERROR `core::ops::Fn<(isize,)>`
//~| ERROR `core::ops::Fn<(isize,)>`
}
4 changes: 3 additions & 1 deletion src/test/compile-fail/issue-15094.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ struct Debuger<T> {
x: T
}

impl<T: fmt::Debug> ops::Fn<(), ()> for Debuger<T> {
impl<T: fmt::Debug> ops::Fn<(),> for Debuger<T> {
type Output = ();

fn call(&self, _args: ()) {
//~^ ERROR `call` has an incompatible type for trait: expected "rust-call" fn, found "Rust" fn
println!("{:?}", self.x);
Expand Down
2 changes: 1 addition & 1 deletion src/test/compile-fail/issue-17545.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#![feature(unboxed_closures)]

pub fn foo<'a, F: Fn<(&'a (),), ()>>(bar: F) {
pub fn foo<'a, F: Fn(&'a ())>(bar: F) {
bar.call((
&(), //~ ERROR borrowed value does not live long enough
));
Expand Down
4 changes: 3 additions & 1 deletion src/test/compile-fail/overloaded-calls-bad.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ struct S {
y: isize,
}

impl FnMut<(isize,),isize> for S {
impl FnMut<(isize,)> for S {
type Output = isize;

extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize {
self.x * self.y * z
}
Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/overloaded-calls-nontuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ struct S {
y: isize,
}

impl FnMut<isize,isize> for S {
impl FnMut<isize> for S {
type Output = isize;
extern "rust-call" fn call_mut(&mut self, z: isize) -> isize {
self.x + self.y + z
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
// except according to those terms.


struct invariant<'a> {
struct Invariant<'a> {
f: Box<for<'b> FnOnce() -> &'b mut &'a isize + 'static>,
}

fn to_same_lifetime<'r>(bi: invariant<'r>) {
let bj: invariant<'r> = bi;
fn to_same_lifetime<'r>(bi: Invariant<'r>) {
let bj: Invariant<'r> = bi;
}

fn to_longer_lifetime<'r>(bi: invariant<'r>) -> invariant<'static> {
fn to_longer_lifetime<'r>(bi: Invariant<'r>) -> Invariant<'static> {
bi //~ ERROR mismatched types
}

Expand Down
3 changes: 2 additions & 1 deletion src/test/compile-fail/unboxed-closure-feature-gate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
// Check that parenthetical notation is feature-gated except with the
// `Fn` traits.

trait Foo<A,R> {
trait Foo<A> {
type Output;
}

fn main() {
Expand Down
11 changes: 6 additions & 5 deletions src/test/compile-fail/unboxed-closure-sugar-default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#![feature(unboxed_closures)]
#![allow(dead_code)]

trait Foo<T,U,V=T> {
fn dummy(&self, t: T, u: U, v: V);
trait Foo<T,V=T> {
type Output;
fn dummy(&self, t: T, v: V);
}

trait Eq<X: ?Sized> { }
Expand All @@ -24,14 +25,14 @@ fn eq<A: ?Sized,B: ?Sized>() where A : Eq<B> { }

fn test<'a,'b>() {
// Parens are equivalent to omitting default in angle.
eq::< Foo<(isize,),()>, Foo(isize) >();
eq::< Foo<(isize,),Output=()>, Foo(isize) >();

// In angle version, we supply something other than the default
eq::< Foo<(isize,),(),isize>, Foo(isize) >();
eq::< Foo<(isize,),isize,Output=()>, Foo(isize) >();
//~^ ERROR not implemented

// Supply default explicitly.
eq::< Foo<(isize,),(),(isize,)>, Foo(isize) >();
eq::< Foo<(isize,),(isize,),Output=()>, Foo(isize) >();
}

fn main() { }
30 changes: 16 additions & 14 deletions src/test/compile-fail/unboxed-closure-sugar-equiv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#![feature(unboxed_closures)]
#![allow(dead_code)]

trait Foo<T,U> {
fn dummy(&self, t: T, u: U);
trait Foo<T> {
type Output;
fn dummy(&self, t: T, u: Self::Output);
}

trait Eq<X: ?Sized> { }
Expand All @@ -26,31 +27,32 @@ fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }

fn test<'a,'b>() {
// No errors expected:
eq::< Foo<(),()>, Foo() >();
eq::< Foo<(isize,),()>, Foo(isize) >();
eq::< Foo<(isize,usize),()>, Foo(isize,usize) >();
eq::< Foo<(isize,usize),usize>, Foo(isize,usize) -> usize >();
eq::< Foo<(&'a isize,&'b usize),usize>, Foo(&'a isize,&'b usize) -> usize >();
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 >();

// Test that anonymous regions in `()` form are equivalent
// to fresh bound regions, and that we can intermingle
// named and anonymous as we choose:
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
for<'x,'y> Foo(&'x isize,&'y usize) -> usize >();
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
for<'x> Foo(&'x isize,&usize) -> usize >();
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
for<'y> Foo(&isize,&'y usize) -> usize >();
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),usize>,
eq::< for<'x,'y> Foo<(&'x isize,&'y usize),Output=usize>,
Foo(&isize,&usize) -> usize >();

// lifetime elision
eq::< for<'x> Foo<(&'x isize,), &'x isize>,
eq::< for<'x> Foo<(&'x isize,), Output=&'x isize>,
Foo(&isize) -> &isize >();

// Errors expected:
eq::< Foo<(),()>, Foo(char) >();
//~^ ERROR not implemented
eq::< Foo<(),Output=()>,
Foo(char) >();
//~^^ ERROR not implemented
}

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
#![feature(unboxed_closures)]
#![allow(dead_code)]

trait Foo<T,U> {
fn dummy(&self, t: T, u: U);
trait Foo<T> {
type Output;
fn dummy(&self, t: T);
}

trait Eq<X: ?Sized> { }
impl<X: ?Sized> Eq<X> for X { }
fn eq<A: ?Sized,B: ?Sized +Eq<A>>() { }

fn main() {
eq::< for<'a> Foo<(&'a isize,), &'a isize>,
eq::< for<'a> Foo<(&'a isize,), Output=&'a isize>,
Foo(&isize) -> &isize >();
eq::< for<'a> Foo<(&'a isize,), (&'a isize, &'a isize)>,
eq::< for<'a> Foo<(&'a isize,), Output=(&'a isize, &'a isize)>,
Foo(&isize) -> (&isize, &isize) >();

let _: Foo(&isize, &usize) -> &usize; //~ ERROR missing lifetime specifier
Expand Down
4 changes: 2 additions & 2 deletions src/test/compile-fail/unboxed-closure-sugar-not-used-on-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@

// Test that the `Fn` traits require `()` form without a feature gate.

fn bar1(x: &Fn<(),()>) {
fn bar1(x: &Fn<()>) {
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
}

fn bar2<T>(x: &T) where T: Fn<(),()> {
fn bar2<T>(x: &T) where T: Fn<()> {
//~^ ERROR angle-bracket notation is not stable when used with the `Fn` family
}

Expand Down
12 changes: 7 additions & 5 deletions src/test/compile-fail/unboxed-closure-sugar-region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@

use std::marker;

trait Foo<'a,T,U> {
fn dummy(&'a self) -> &'a (T,U);
trait Foo<'a,T> {
type Output;
fn dummy(&'a self) -> &'a (T,Self::Output);
}

trait Eq<X: ?Sized> { }
Expand All @@ -29,16 +30,17 @@ fn same_type<A,B:Eq<A>>(a: A, b: B) { }

fn test<'a,'b>() {
// Parens are equivalent to omitting default in angle.
eq::< Foo<(isize,),()>, Foo(isize) >();
eq::< Foo<(isize,),Output=()>, Foo(isize) >();

// Here we specify 'static explicitly in angle-bracket version.
// Parenthesized winds up getting inferred.
eq::< Foo<'static, (isize,),()>, Foo(isize) >();
eq::< Foo<'static, (isize,),Output=()>, Foo(isize) >();
}

fn test2(x: &Foo<(isize,),()>, y: &Foo(isize)) {
fn test2(x: &Foo<(isize,),Output=()>, y: &Foo(isize)) {
// Here, the omitted lifetimes are expanded to distinct things.
same_type(x, y) //~ ERROR cannot infer
//~^ ERROR cannot infer
}

fn main() { }
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@

// Test that parentheses form doesn't work with struct types appearing in local variables.

struct Bar<A,R> {
f: A, r: R
struct Bar<A> {
f: A
}

fn bar() {
let x: Box<Bar()> = panic!();
//~^ ERROR parenthesized parameters may only be used with a trait
//~^^ ERROR associated type bindings are not allowed here
}

fn main() { }
Expand Down
5 changes: 3 additions & 2 deletions src/test/compile-fail/unboxed-closure-sugar-used-on-struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

// Test that parentheses form doesn't work with struct types appearing in argument types.

struct Bar<A,R> {
f: A, r: R
struct Bar<A> {
f: A
}

fn foo(b: Box<Bar()>) {
//~^ ERROR parenthesized parameters may only be used with a trait
//~^^ ERROR associated type bindings are not allowed here
}

fn main() { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

trait One<A> { fn foo(&self) -> A; }

fn foo(_: &One()) //~ ERROR wrong number of type arguments
fn foo(_: &One()) //~ ERROR no associated type `Output` defined in `One<()>`
{}

fn main() { }
2 changes: 1 addition & 1 deletion src/test/compile-fail/unboxed-closure-sugar-wrong-trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
trait Trait {}

fn f<F:Trait(isize) -> isize>(x: F) {}
//~^ ERROR wrong number of type arguments: expected 0, found 2
//~^ ERROR wrong number of type arguments: expected 0, found 1

fn main() {}

8 changes: 6 additions & 2 deletions src/test/compile-fail/unboxed-closures-fnmut-as-fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use std::ops::{Fn,FnMut,FnOnce};

struct S;

impl FnMut<(isize,),isize> for S {
impl FnMut<(isize,)> for S {
type Output = isize;

extern "rust-call" fn call_mut(&mut self, (x,): (isize,)) -> isize {
x * x
}
Expand All @@ -29,6 +31,8 @@ fn call_it<F:Fn(isize)->isize>(f: &F, x: isize) -> isize {
}

fn main() {
let x = call_it(&S, 22); //~ ERROR not implemented
let x = call_it(&S, 22);
//~^ ERROR not implemented
//~| ERROR not implemented
}

Loading

0 comments on commit 09783d1

Please sign in to comment.