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

Add explicit notion of copyability for closures. #2829

Closed
bblum opened this issue Jul 7, 2012 · 3 comments
Closed

Add explicit notion of copyability for closures. #2829

bblum opened this issue Jul 7, 2012 · 3 comments
Labels
A-typesystem Area: The type system E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Milestone

Comments

@bblum
Copy link
Contributor

bblum commented Jul 7, 2012

Proposal: A closure is copyable iff everything in its environment is copyable. Furthermore, non-copyable ("one-shot") closures are allowed to capture and de-initialise outer variables.

This will allow building closures that run destructors for you. It will also fix #2828.

Closures' types can then be written with copy and send traits. fn x(f: fn()) { f(); f(); } will no longer be legal; you have to write fn x(f: fn()<copy>) or some-such.

@bblum
Copy link
Contributor Author

bblum commented Jul 20, 2012

This will also have problems with the new proposed task builder interface (and also, if i'm not mistaken, with the old one too!).

This will fail:

let t = task::task().notify_port(p);
t.spawn(body);
t.spawn(body);

This will not fail but should:

let t = task::task().notify_port(p);
for iter::repeat(100) { t.spawn(body) }

@nikomatsakis
Copy link
Contributor

~fn() closures are becoming non-copyable, making this a non-issue.

@bblum
Copy link
Contributor Author

bblum commented Feb 5, 2013

Yeah, as long as #2549 stays open, this doesn't need to be open.

celinval pushed a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Update Rust toolchain from nightly-2023-10-17 to nightly-2023-10-18
without any other source changes.
This is an automatically generated pull request. If any of the CI checks
fail, manual intervention is required. In such a case, review the
changes at https://github.com/rust-lang/rust from
rust-lang@49691b1
up to
rust-lang@09df610.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-typesystem Area: The type system E-hard Call for participation: Hard difficulty. Experience needed to fix: A lot.
Projects
None yet
Development

No branches or pull requests

2 participants