Skip to content

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

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
jethrogb opened this issue Mar 21, 2017 · 7 comments
Labels
A-type-system Area: Type system C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@jethrogb
Copy link
Contributor

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
Copy link
Contributor

See #38848 (comment) for the reasons.

@jethrogb
Copy link
Contributor Author

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
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor

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

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

@Mark-Simulacrum Mark-Simulacrum added A-type-system Area: Type system T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 23, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-feature-request Category: A feature request, i.e: not implemented / a PR. label Jul 27, 2017
@asquared31415
Copy link
Contributor

Update: the example code now compiles.

@Dylan-DPC
Copy link
Member

Closing this as the example now compiles

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-type-system Area: Type system C-feature-request Category: A feature request, i.e: not implemented / a PR. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

6 participants