-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
Implementing Fn<Args, R> for multiple Args results in confusing error #18952
Comments
I should note the same happens for overloading on the return type: #![feature(unboxed_closures)]
use std::ops::Fn;
struct Foo;
impl Fn(i32, i32) for Foo {
extern "rust-call" fn call(&self, args: (i32, i32)) {
println!("{:?}", args);
}
}
impl Fn(i32, i32) -> i32 for Foo {
extern "rust-call" fn call(&self, args: (i32, i32)) -> i32 {
println!("{:?}", args);
0
}
}
fn main() {
let foo = Foo;
let x: i32 = foo(1, 1);
} |
Triage: same error today. Here's the updated code: #![feature(unboxed_closures)]
use std::ops::Fn;
struct Foo;
impl Fn<(isize, isize)> for Foo {
extern "rust-call" fn call(&self, args: (isize, isize)) -> Self::Output {
println!("{:?}", args);
}
}
impl FnMut<(isize, isize)> for Foo {
extern "rust-call" fn call_mut(&mut self, args: (isize, isize)) -> Self::Output {
println!("{:?}", args);
}
}
impl FnOnce<(isize, isize)> for Foo {
type Output = ();
extern "rust-call" fn call_once(self, args: (isize, isize)) -> Self::Output {
println!("{:?}", args);
}
}
impl Fn<(isize, isize, isize)> for Foo {
extern "rust-call" fn call(&self, args: (isize, isize, isize)) -> Self::Output {
println!("{:?}", args);
}
}
impl FnMut<(isize, isize, isize)> for Foo {
extern "rust-call" fn call_mut(&mut self, args: (isize, isize, isize)) -> Self::Output {
println!("{:?}", args);
}
}
impl FnOnce<(isize, isize, isize)> for Foo {
type Output = ();
extern "rust-call" fn call_once(self, args: (isize, isize, isize)) -> Self::Output {
println!("{:?}", args);
}
}
fn main() {
let foo = Foo;
foo(1, 1);
} |
Still same error on rustc 1.21.0-nightly (469a6f9 2017-08-22) |
Is this still occurring? |
Looking at the link provided by Steve - it seems it's still failing on the nightly on playground (https://play.rust-lang.org/?gist=fe78a973c074edba7b422252bdf40bf1&version=nightly) |
I agree, the error message is still pretty confusing. Ideally, the error would be at the point of defining the second |
Allow to dispatch fn traits depending on number of parameters Hello, By following @eddyb's advise on issue rust-lang#45510, I managed to have the snippets of code in rust-lang#45510 and rust-lang#18952 passing without breaking older diagnostics. EDIT: the codegen tests breakage I experienced is due to the poor quality of my laptop. If any kind reviewer has any advice, you are very welcome.
Allow to dispatch fn traits depending on number of parameters Hello, By following @eddyb's advise on issue #45510, I managed to have the snippets of code in #45510 and #18952 passing without breaking older diagnostics. EDIT: the codegen tests breakage I experienced is due to the poor quality of my laptop. If any kind reviewer has any advice, you are very welcome.
This case now compiles successfully, and most of the errors that you would encounter by forgetting to use the correct
|
feat: complete raw, const keyword
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:
edit: updated source for rust changes on 2014-12-03
edit: another update 2015-01-20
The text was updated successfully, but these errors were encountered: