-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Unboxed closures with no or only-Copy captures should be Copy #19128
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
Comments
This is solved, unboxed closures are currently copyable: fn is_copy<T: Copy>(_: T) {}
fn main() {
let i = 5i;
is_copy(move |:| i);
is_copy(|&:| {});
is_copy(|&mut :| {});
is_copy(|:| i);
is_copy(|:| {});
} But according to #19817 and #19889, the plan is that they shouldn't be implicitly copyable (which I don't quite agree with). |
So apparently the changes to make the trait Copy opt-in for closures have been implemented, which means that the code above doesn't work any more. |
Triage: closures aren't copyable again, but I am not sure if they're intended to be or not. @rust-lang/lang? |
They were deliberately made non-copy in issue #19817 |
There's a few possible ways to have duplicatable closures (all aren't great, unfortunately):
These have various downsides e.g. the first two only work for |
Thanks @bluss ! |
Right now no unboxed closures are Copy, but there's no reason that 0-size closures or those with only copy captures couldn't be Copy.
The text was updated successfully, but these errors were encountered: