Skip to content

Unboxed closures with all Clone members should implement Clone #23501

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
seanmonstar opened this issue Mar 19, 2015 · 6 comments
Closed

Unboxed closures with all Clone members should implement Clone #23501

seanmonstar opened this issue Mar 19, 2015 · 6 comments
Labels
A-closures Area: Closures (`|…| { … }`) C-feature-request Category: A feature request, i.e: not implemented / a PR. P-low Low priority T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@seanmonstar
Copy link
Contributor

Similar to #19128

#![feature(core, unboxed_closures)]
use std::ops::Fn;

#[derive(Clone)]
struct NotCopy;

#[derive(Clone)]
struct Derp {
    foo: NotCopy
}

impl Fn<()> for Derp {
    type Output = ();
    extern "rust-call" fn call(&self, _: ()) {
    }
}

fn with_clone<F>(_f: F) where F: Fn() + Clone {

}

fn main() {
    let foo = NotCopy;
    with_clone(Derp { foo: NotCopy }); // works
    with_clone(move || { // errors
        let _ = foo; // <- should be like Derp, accessing self.foo
    });
}
@kmcallister kmcallister added the A-closures Area: Closures (`|…| { … }`) label Mar 19, 2015
@bluss
Copy link
Member

bluss commented Apr 27, 2015

This is important for iterators -- with this we can clone most iterator pipelines. In fact, most don't even need captures at all and would be the cheapest to clone.

@withoutboats
Copy link
Contributor

This would be good for situations in which one wants to box and store a closure in a small minority of cases. Would be good to be able to have something like Cow<'a, Fn(...)>.

@arielb1
Copy link
Contributor

arielb1 commented Nov 14, 2015

Sounds like an nice idea. Unfortunately it would require Clone to be a lang-item, but it is already half a lang-item as a supertrait to Copy.

@seanmonstar
Copy link
Contributor Author

The expanded closure struct couldn't have the equivalent of 'derive(Clone)'
added to it?

On Sat, Nov 14, 2015, 9:32 AM arielb1 notifications@github.com wrote:

Sounds like an nice idea. Unfortunately it would require Clone to be a
lang-item, but it is already half a lang-item as a supertrait to Copy.


Reply to this email directly or view it on GitHub
#23501 (comment).

@arielb1
Copy link
Contributor

arielb1 commented Nov 14, 2015

@seanmonstar

derive(Clone) runs before upvars are known.

@brson brson added I-wishlist T-lang Relevant to the language team, which will review and decide on the PR/issue. P-low Low priority A-closures Area: Closures (`|…| { … }`) and removed A-closures Area: Closures (`|…| { … }`) labels May 4, 2017
@Mark-Simulacrum Mark-Simulacrum added C-bug Category: This is a bug. C-feature-request Category: A feature request, i.e: not implemented / a PR. and removed C-bug Category: This is a bug. I-wishlist labels Jul 22, 2017
@oli-obk
Copy link
Contributor

oli-obk commented Nov 24, 2017

I think this can be closed now that we have #44490

@arielb1 arielb1 closed this as completed Nov 24, 2017
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-closures Area: Closures (`|…| { … }`) C-feature-request Category: A feature request, i.e: not implemented / a PR. P-low Low priority T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

8 participants