Skip to content
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

Unboxed closures with all Clone members should implement Clone #23501

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

Comments

Projects
None yet
8 participants
@seanmonstar
Copy link
Contributor

seanmonstar commented Mar 19, 2015

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
    });
}
@bluss

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

withoutboats commented Nov 14, 2015

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

This comment has been minimized.

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

This comment has been minimized.

Copy link
Contributor Author

seanmonstar commented Nov 14, 2015

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

This comment has been minimized.

Copy link
Contributor

arielb1 commented Nov 14, 2015

@seanmonstar

derive(Clone) runs before upvars are known.

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Nov 24, 2017

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

@arielb1 arielb1 closed this Nov 24, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.