Skip to content

Implementing Fn<Args, R> for multiple Args results in confusing error #18952

Closed
@tomjakubowski

Description

@tomjakubowski

It may be that overloaded calls aren't meant to be abused this way; even if that's the case I think the error message (at least the second one) could be improved:

#![feature(unboxed_closures)]

use std::ops::Fn;

struct Foo;

impl Fn<(isize, isize), ()> for Foo {
    extern "rust-call" fn call(&self, args: (isize, isize)) {
        println!("{:?}", args);
    }
}

impl Fn<(isize, isize, isize), ()> for Foo {
    extern "rust-call" fn call(&self, args: (isize, isize, isize)) {
        println!("{:?}", args);
    }
}


fn main() {
    let foo = Foo;
    foo(1, 1);
}
<anon>:22:5: 22:14 error: the type of this value must be known in this context
<anon>:22     foo(1, 1);
              ^~~~~~~~~
<anon>:22:5: 22:14 error: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit [E0059]
<anon>:22     foo(1, 1);
              ^~~~~~~~~

edit: updated source for rust changes on 2014-12-03
edit: another update 2015-01-20

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions