Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upLifetime handling doesn't handle function pointers properly #10501
Comments
This comment has been minimized.
This comment has been minimized.
|
cc @nikomatsakis, possibly related to #10153? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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. |
pnkfelix
referenced this issue
Nov 18, 2013
Closed
RFC: Implement Clone on `|A|: 'static -> R` &'static fn()` #8025
ghost
added
the
E-needstest
label
Oct 30, 2014
bors
added a commit
that referenced
this issue
Nov 6, 2014
bors
closed this
in
#18555
Nov 7, 2014
This comment has been minimized.
This comment has been minimized.
|
This was never fixed, but the code got buggy. |
nikomatsakis
reopened this
Dec 2, 2014
nikomatsakis
referenced this issue
Dec 2, 2014
Closed
rustc: Anonymous lifetimes within structs are refused too rigorously #12741
ghost
removed
the
E-needstest
label
Dec 12, 2014
michaelwu
referenced this issue
Sep 22, 2015
Closed
Cannot derive Clone for function pointers with reference args #28590
This comment has been minimized.
This comment has been minimized.
|
Today:
error:
/cc @rust-lang/lang , I know that recently, we changed something related to |
This comment has been minimized.
This comment has been minimized.
|
Current error from @steveklabnik's code:
|
This comment has been minimized.
This comment has been minimized.
|
Seems to work as designed. |
brson
closed this
Apr 11, 2017
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis You may want to reopen this if you feel like there is a path to making it work. |
LeoTestard commentedNov 15, 2013
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.