Skip to content
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

Standard traits not derived for function pointers with different calling conventions #40710

Open
jethrogb opened this issue Mar 21, 2017 · 5 comments

Comments

@jethrogb
Copy link
Contributor

@jethrogb jethrogb commented Mar 21, 2017

use std::fmt::Debug;
use std::hash::Hash;

fn a<T: Hash + Ord + Eq + Clone + Debug>() {}

fn main() {
    a::<fn()>(); //OK
    a::<extern fn()>(); //OK
    a::<extern "C" fn()>(); //OK
    a::<extern "win64" fn()>(); //Error
    a::<extern "system" fn()>(); //Error
}

Errors:

error[E0277]: the trait bound `extern "win64" fn(): std::clone::Clone` is not satisfied
error[E0277]: the trait bound `extern "win64" fn(): std::cmp::Eq` is not satisfied
error[E0277]: the trait bound `extern "win64" fn(): std::cmp::Ord` is not satisfied
error[E0277]: the trait bound `extern "win64" fn(): std::fmt::Debug` is not satisfied
error[E0277]: the trait bound `extern "win64" fn(): std::hash::Hash` is not satisfied
error[E0277]: the trait bound `extern "system" fn(): std::clone::Clone` is not satisfied
error[E0277]: the trait bound `extern "system" fn(): std::cmp::Eq` is not satisfied
error[E0277]: the trait bound `extern "system" fn(): std::cmp::Ord` is not satisfied
error[E0277]: the trait bound `extern "system" fn(): std::fmt::Debug` is not satisfied
error[E0277]: the trait bound `extern "system" fn(): std::hash::Hash` is not satisfied
@petrochenkov

This comment has been minimized.

Copy link
Contributor

@petrochenkov petrochenkov commented Mar 21, 2017

See #38848 (comment) for the reasons.

@jethrogb

This comment has been minimized.

Copy link
Contributor Author

@jethrogb jethrogb commented Mar 21, 2017

I guess the cause for this is similar to reasons that various traits are not defined for very long tuples, arrays over 32 elements, etc. and apparently function pointers with long argument lists. If libcore bloat is an issue, should the compiler instead insert the necessary definitions automatically when needed? Or we need to come up with syntax for "all tuples", etc.

@jonas-schievink

This comment has been minimized.

Copy link
Member

@jonas-schievink jonas-schievink commented Mar 22, 2017

The tuple case can be handled via variadic generics. The fn pointer case, not so much (unless all of them implement a suitable common trait by magic).

@jethrogb

This comment has been minimized.

Copy link
Contributor Author

@jethrogb jethrogb commented Mar 22, 2017

fn-pointer case could also be handled by variadic generics, for the argument list at least. Then you just need one entry per calling convention which hopefully doesn't result in too much bloat. Array case could of course be handled by integer generics.

Are variadic generics something that is seriously considered for Rust's future? If so, we probably still need some kind of stop-gap measure here. If not, we'll need a more definitive solution here.

@jonas-schievink

This comment has been minimized.

Copy link
Member

@jonas-schievink jonas-schievink commented Mar 22, 2017

Are variadic generics something that is seriously considered for Rust's future?

Well, there's rust-lang/rfcs#1935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.