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

Impls for function pointers are patchy #26082

Closed
petrochenkov opened this issue Jun 7, 2015 · 3 comments
Closed

Impls for function pointers are patchy #26082

petrochenkov opened this issue Jun 7, 2015 · 3 comments
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@petrochenkov
Copy link
Contributor

I'd expect function pointers (fn() with all combinations of safety and ABI) to implement roughly the same set of traits as raw pointers, namely:
PartialEq, Eq, Clone, PartialOrd, Ord, Hash, fmt::Pointer, Debug

Currently Clone is implemented for safe and unsafe function pointers, but all the ABIs except for "Rust" and "C" are ignored, i.e. a paradoxical situation takes place - extern "rare_abi" fn() is Copy, but not Clone (Edit: and it causes ICEs).
PartialEq is implemented only for safe function pointers with "C" ABI.
All the other traits are not implemented.

@petrochenkov
Copy link
Contributor Author

(I'm going to implement all of these if there are no objections.)

@bluss
Copy link
Member

bluss commented Jun 7, 2015

See also #24000 -- fn() types are also further parameterized by their number of lifetime parameters unfortunately, so it's very hard to cover even all possibilities of regular rust ABI functions.

@petrochenkov
Copy link
Contributor Author

Hm, interesting

impl<T> Clone for for<'a> fn(&'a T) {}

works for plain references and other "concrete" uses of lifetimes, but I don't see any way to cover something like this

impl<T> Clone for for<'a> fn(T) where T: 'a {} // made up syntax

generically.

@steveklabnik steveklabnik added A-libs C-enhancement Category: An issue proposing an enhancement or a PR with one. labels Jun 8, 2015
bors added a commit that referenced this issue Sep 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

3 participants