-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Lifetime handling doesn't handle function pointers properly #10501
Comments
cc @nikomatsakis, possibly related to #10153? |
Hmm. The error message is...horribly cryptic but the error seems legit. (Probably worth thinking, independently, on SOMETHING better to print out there, but I'm not sure what). I was wrong, not related to #10153. This is kind of a flaw in the way that the "clone" operation is defined over fn types, but I'm not actually sure how it can be fixed without modifying the compiler to introduce some special bounds. Let me elaborate a bit on the problem, as much for myself as anyone else (it's somewhat subtle). The definition of clone for fn pointers is roughly like:
What happens here is that the type in question is (written out fully explicitly) This is hard to fix. I'm not 100% sure what the "right" fix would even be, actually. But one possible fix is to add a builtin bound to the compiler, let's call it Given this bound, we might have an impl for clone like:
this avoids the problem by not binding type parameters to the individual argument types. It's also more general. |
This was never fixed, but the code got buggy. |
Today:
error:
/cc @rust-lang/lang , I know that recently, we changed something related to |
Current error from @steveklabnik's code:
|
Seems to work as designed. |
@nikomatsakis You may want to reopen this if you feel like there is a path to making it work. |
Let's say I've got a struct or enum containing functions (pure Rust functions, not closures, so passed by a simple pointer)
The above code works. I can pass-around instances of Baz and call the function.
Now if I wan Baz to be copy-able, which should be possible since it only contains a pointer, and add the
#[deriving(Clone)]
attribute to it, I got a strange compiler error:This worked perfectly well (including the deriving(Clone) attribute) while the function only took parameters by owned boxes or by-value. I only get this message since I added a borrowed parameter to the function. I don't see the problem here. If a function is simply passed by-pointer we should be able to copy this pointer.
I'm not sure this is the right title for this issue. Feel free to change it if it's miss chosen.
The text was updated successfully, but these errors were encountered: