Skip to content

strange errors with multiple impls of FnOnce #31560

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
durka opened this issue Feb 11, 2016 · 2 comments
Closed

strange errors with multiple impls of FnOnce #31560

durka opened this issue Feb 11, 2016 · 2 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@durka
Copy link
Contributor

durka commented Feb 11, 2016

If one maliciously attempts to hack function overloading into rust

#![feature(unboxed_closures, fn_traits)]

use std::ops::FnOnce;

struct Nope;

impl FnOnce<()> for Nope {
    type Output = ();

    extern "rust-call" fn call_once(self, _: ()) {}
}

impl FnOnce<((),())> for Nope {
    type Output = ();

    extern "rust-call" fn call_once(self, _: ((),())) {}
}

fn main() {
    Nope();
}

then one receives appropriately inscrutable errors:

<anon>:20:5: 20:11 error: the type of this value must be known in this context
<anon>:20     Nope();
              ^~~~~~
<anon>:20:5: 20:11 error: cannot use call notation; the first type parameter for the function trait is neither a tuple nor unit [E0059]
<anon>:20     Nope();
              ^~~~~~
<anon>:20:5: 20:11 help: see the detailed explanation for E0059
error: aborting due to 2 previous errors
playpen: application terminated with error code 101

I don't understand which value rustc wants a type for, and the second error is clearly untrue. I assume this use case is not going to be supported, even if these features are stabilized, but the diagnostic is not good.

@steveklabnik steveklabnik added A-libs A-diagnostics Area: Messages for errors, warnings, and lints labels Feb 15, 2016
@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@steveklabnik steveklabnik added T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. and removed A-libs labels Mar 24, 2017
@qnighy
Copy link
Contributor

qnighy commented May 18, 2017

Looks like a duplicate of #18952.

@Mark-Simulacrum
Copy link
Member

Closing in favor, as duplicate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants