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 closure types are implicitly copyable #19817

Closed
nikomatsakis opened this issue Dec 13, 2014 · 7 comments · Fixed by #19889
Closed

Unboxed closure types are implicitly copyable #19817

nikomatsakis opened this issue Dec 13, 2014 · 7 comments · Fixed by #19889
Assignees

Comments

@nikomatsakis
Copy link
Contributor

Unboxed closure types should be consistent with structs and hence should not by implicitly copyable. They were essentially forgotten by the opt-in copy work.

@nikomatsakis
Copy link
Contributor Author

Nominating for 1.0 p-backcompat-lang.

@nikomatsakis
Copy link
Contributor Author

Example test:

fn do_it(x: &int) { }

fn main() {
    let f = move|:| ();
    f();
    f();
}

This test passes but should not, I think.

@japaric
Copy link
Member

japaric commented Dec 14, 2014

What happens if you actually want the unboxed closure to be copyable? How do you opt-in? Following your example, how do I say: "I want f/|| {} (which has an anonymous type) to be copyable".

@bluss
Copy link
Member

bluss commented Dec 14, 2014

With clonable iterators in mind (PR #19837), I wonder if unboxed closures can impl Clone automatically?

@flaper87 flaper87 self-assigned this Dec 15, 2014
flaper87 added a commit to flaper87/rust that referenced this issue Dec 16, 2014
The fix just checks if the bound is `Copy` and returns an `Err` if so.

Closes: rust-lang#19817
@ghost
Copy link

ghost commented Dec 16, 2014

Like @japaric, I'm also interested in having copyable closures somehow without having to resort to low-level magic.

@ftxqxd
Copy link
Contributor

ftxqxd commented Dec 16, 2014

I think that closures should implement Copy automatically. There are plenty of semi-built-in compound types today that are implicitly copyable ([Copyable, ..n], (Copyable1, Copyable2, ...)), so it’s actually more consistent for unboxed closures to behave the same, because unboxed closures are basically just (fn(args) -> ret, upvar1, upvar2).

And if there’s literally no way to get unboxed closures to opt in to Copy, then I don’t think it’s a good idea to disallow that.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Dec 17, 2014
The fix just checks if the bound is `Copy` and returns an `Err` if so.

Closes: rust-lang#19817

@nikomatsakis r?
@alexcrichton
Copy link
Member

Closed by #19889

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants