Skip to content

Implement Copy/Clone for closures - #44551

Merged
bors merged 2 commits into
rust-lang:masterfrom
scalexm:copy-clone-closures
Sep 21, 2017
Merged

Implement Copy/Clone for closures#44551
bors merged 2 commits into
rust-lang:masterfrom
scalexm:copy-clone-closures

Conversation

@scalexm

Copy link
Copy Markdown
Contributor

Implement RFC #2132 (tracking issue: #44490).

NB: I'm not totally sure about the whole feature gates thing, that's my first PR of this kind...

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @pnkfelix

(rust_highfive has picked a reviewer for you, use r? to override)

@aidanhs

Copy link
Copy Markdown
Contributor

Thanks for the PR @scalexm, we'll check in now and again to make sure @pnkfelix or another reviewer gets to this soon!

@aidanhsaidanhs added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 13, 2017
Comment threadsrc/librustc/traits/select.rs Outdated

@arielb1arielb1Sep 14, 2017

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you need to check the feature-gate status of the crate that defined the closure, to avoid ICEs?

Crate A:

#![feature(clone_closures)]pubtraitGeneric{fnfoo<T:Clone>(self,t:T);}pubfnexample<G:Generic>(g:G){
g.foo(|| {});}

Crate B:

// no feature flags!externcrate a;structS;implGenericforS{fnfoo<T:Clone>(self,t:T){let _ = t.clone();}}fnmain(){// trans will monomorphize this, and will try to evaluate `[closure]: Clone`, which// will fail and cause an ICE.
foo::example(S);}

Another option would be to make all closures Copy & Clone in trans, but that would be visible through specialization etc. so I'm not sure it's the better idea.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@arielb1 Yes you're right. I'm working on it.

Comment threadsrc/librustc_mir/shim.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason for this assertion? This method works just as well for structs and univariant enums.

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed, but it won't work for arrays. I guess the match can be extended in the future if needed.

@bors

bors commented Sep 17, 2017

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #44634) made this pull request unmergeable. Please resolve the merge conflicts.

@arielb1arielb1 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 19, 2017
@arielb1

Copy link
Copy Markdown
Contributor

@bors r+

@bors

bors commented Sep 20, 2017

Copy link
Copy Markdown
Collaborator

📌 Commit 3fa3fe0 has been approved by arielb1

@arielb1arielb1 added the relnotes Marks issues that should be documented in the release notes of the next release. label Sep 20, 2017
bors added a commit that referenced this pull request Sep 21, 2017
Implement `Copy`/`Clone` for closures
Implement RFC [#2132](rust-lang/rfcs#2132) (tracking issue: #44490).
NB: I'm not totally sure about the whole feature gates thing, that's my first PR of this kind...
@bors

bors commented Sep 21, 2017

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 3fa3fe0 with merge e2504cf...

@bors

bors commented Sep 21, 2017

Copy link
Copy Markdown
Collaborator

☀️ Test successful - status-appveyor, status-travis
Approved by: arielb1
Pushing e2504cf to master...

@bors
bors merged commit 3fa3fe0 into rust-lang:masterSep 21, 2017
@borsbors mentioned this pull request Sep 21, 2017
@scalexm
scalexm deleted the copy-clone-closures branch October 22, 2018 12:16
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

relnotesMarks issues that should be documented in the release notes of the next release.S-waiting-on-authorStatus: This is awaiting some action (such as code changes or more information) from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@scalexm@rust-highfive@aidanhs@bors@arielb1@pnkfelix