-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Stabilize the copy_closures and clone_closures features #49299
Conversation
In addition to the `Fn*` family of traits, closures now implement `Copy` (and similarly `Clone`) if all of the captures do.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @withoutboats (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
src/librustc/traits/select.rs
Outdated
Some(trait_id) == self.tcx().lang_items().clone_trait() && | ||
self.tcx().has_clone_closures(def_id.krate); | ||
let copy_closures = Some(trait_id) == self.tcx().lang_items().copy_trait(); | ||
let clone_closures = Some(trait_id) == self.tcx().lang_items().clone_trait(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m not confident about this particular chunk, but tests appear to be happy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems ok. The name of the variable is weird; I would prefer is_copy_trait
and is_clone_trait
or something.
src/libcore/marker.rs
Outdated
@@ -166,6 +166,11 @@ pub trait Unsize<T: ?Sized> { | |||
/// are allowed to access `x` after the assignment. Under the hood, both a copy and a move | |||
/// can result in bits being copied in memory, although this is sometimes optimized away. | |||
/// | |||
/// ## Closures | |||
/// | |||
/// Closure types automatically implement `Clone` if they capture no value from the environment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clone
is that a typo for Copy
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, hasty copy-paste. Good catch, thanks. I just squashed a fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mind changing the names of those variables? otherwise r=me :)
Yes, this code is much less confusing with those variable names. Done, thanks. |
@bors r=nikomatsakis |
📌 Commit 1efe0b3 has been approved by |
Stabilize the copy_closures and clone_closures features In addition to the `Fn*` family of traits, closures now implement `Copy` (and similarly `Clone`) if all of the captures do. Tracking issue: rust-lang#44490
Stabilize the copy_closures and clone_closures features In addition to the `Fn*` family of traits, closures now implement `Copy` (and similarly `Clone`) if all of the captures do. Tracking issue: rust-lang#44490
In addition to the
Fn*
family of traits, closures now implementCopy
(and similarlyClone
) if all of the captures do.Tracking issue: #44490