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 upfunctions implement Copy but not Clone #28229
Comments
This comment has been minimized.
This comment has been minimized.
|
Even worse, because fn c<T: Copy>(t: T) -> (T, T) { (t.clone(), t) }
fn f() {}
fn main() {
c(0);
c(f);
}
This (including the ICE) was already reported in #24000, so this looks like a duplicate |
This comment has been minimized.
This comment has been minimized.
|
Nominating as this seems relatively serious, but the failure mode is just an ICE then it doesn't seem super super pressing. |
alexcrichton
added
I-nominated
T-compiler
labels
Sep 4, 2015
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis: should we make |
This comment has been minimized.
This comment has been minimized.
|
We could just add something like the following to the libcore, I think: impl<R> Clone for fn() -> R {
fn clone(&self) -> Self { self }
}
impl<R, A1> Clone for fn(A1) -> R {
fn clone(&self) -> Self { self }
}
impl<R, A1, A2> Clone for fn(A1, A2) -> R {
fn clone(&self) -> Self { self }
}
impl<R, A1, A2, A3> Clone for fn(A1, A2, A3) -> R {
fn clone(&self) -> Self { self }
}We do exactly the same thing for arrays. |
This comment has been minimized.
This comment has been minimized.
|
Err, nevermind, that doesn't really do the right thing: that only works for function pointers, not function definitions. |
This comment has been minimized.
This comment has been minimized.
|
I’m pretty sure this cannot be done backwards compatibly because such impl would conflict with all the explicit |
This comment has been minimized.
This comment has been minimized.
|
@nagisa it should be fine with specialisation. |
This comment has been minimized.
This comment has been minimized.
|
It would be fine with lattice impls. Which is a different feature from specialization. Actually, even that wouldn't be backwards-compatible, given that you would need to provide the meet impls (e.g. |
This comment has been minimized.
This comment has been minimized.
|
I don't understand what you mean, allowing more specialised impls (i.e. this) is exactly what specialisation is. Anyway nitpicking the exact terminology probably doesn't matter so much here... |
This comment has been minimized.
This comment has been minimized.
|
@aturon's specialization RFC - rust-lang/rfcs#1210 - does not allow for overlapping impls in any case. There are also proposals for "lattice impls", which allow overlapping impls as long as there is a meet between every 2 impls. This is not part of the RFC. |
This comment has been minimized.
This comment has been minimized.
|
Ah, I was speaking more abstractly, but in fact, @aturon has realised a modification to the RFC that allows cases like this, just hasn't had time to publish. |
This comment has been minimized.
This comment has been minimized.
|
On Fri, Sep 04, 2015 at 01:33:13PM -0700, arielb1 wrote:
Possibly. My preferred strategy here would be to leverage |
This comment has been minimized.
This comment has been minimized.
|
Variants which include all these proposed in the RFC. |
nikomatsakis
added
the
T-lang
label
Sep 17, 2015
This comment has been minimized.
This comment has been minimized.
|
triage: P-medium We're still working out the preferred way to solve this problem. I tagged T-lang because of the interaction w/ specialization. |
rust-highfive
added
P-medium
and removed
I-nominated
labels
Sep 17, 2015
jonas-schievink
referenced this issue
Nov 14, 2015
Closed
Make Clone a lang-item and implement it for closures whose members are all Clone #1369
brson
added
A-typesystem
I-wishlist
P-low
I-ICE
and removed
I-wishlist
labels
Jul 14, 2016
This comment has been minimized.
This comment has been minimized.
|
Triage: P-low. ICE is problematic though would be great to fix it. Can anybody mentor? |
nagisa
referenced this issue
Jul 17, 2016
Closed
Varargs extern functions are Copy but not Clone #34874
This comment has been minimized.
This comment has been minimized.
|
@brson fixing this is no small thing, sadly. I had hoped we could address it through specialization but that does not seem to be the case. @arielb1 has been advocating for building the clone impls into the compiler, that might be the most prudent short-term path at least, particularly given that |
nikomatsakis
added
E-mentor
and removed
P-medium
labels
Jul 28, 2016
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis oh, that would be great. I was only hoping to stop the ICE! |
This comment has been minimized.
This comment has been minimized.
|
If |
stjepang
referenced this issue
Dec 15, 2016
Open
fn pointers taking references are not `Clone` #38382
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis If this is still an issue and you have the time, I would like to look at this. I would be pretty new to Rust and the Compiler though |
This comment has been minimized.
This comment has been minimized.
|
@cseale Great! Since writing my last comment, I now have greater hope for being able to fix this through specialization (and hence without modifying the compiler), but those plans remain a bit in flux, so I think it's probably best to close this hole in the compiler for the time being. I will try to write up some instructions tomorrow! |
This comment has been minimized.
This comment has been minimized.
|
Hi @nikomatsakis, any chance we could take a look at this? |
This comment has been minimized.
This comment has been minimized.
|
@cseale argh, sorry, added to my to-do list for tomorrow =) I think part of my hesitation is that it's going to be potentially a bit messy to hack this in, and if specialization can solve it that will be much nicer (and of course it's been this long...). But let me glance over code tomorrow to try and decide just how invasive it will be. |
This comment has been minimized.
This comment has been minimized.
|
@nikomatsakis no problem! if there is another outstanding E-mentor issue involving that compiler maybe I would be better spending my time there? I am just trying to get involved in that part of the codebase |
jonas-schievink
referenced this issue
Mar 24, 2017
Closed
`[_; 33]` implements `Copy`, but not `Clone` #40796
ketralnis
pushed a commit
to ketralnis/pipelines-rs
that referenced
this issue
Jun 12, 2017
Mark-Simulacrum
added
C-bug
and removed
C-bug
I-wrong
labels
Jul 22, 2017
This comment has been minimized.
This comment has been minimized.
|
I've written a fix for this locally, however I wonder how it would be integrated in the compiler (if it is).
I cannot merge the two steps since the compiler would not understand the attribute |
This comment has been minimized.
This comment has been minimized.
|
@scalexm Use Basically you slap a |
fuchsnj commentedSep 4, 2015
This compiles
but this does not (playground)
The only difference is the bounds on T. The Copy trait requires that the Clone trait is also implemented, so I believe both of these should compile.