Implement non-capturing closure to fn coercion#40025
Merged
bors merged 4 commits intorust-lang:masterfrom Feb 25, 2017
Merged
Conversation
Contributor
|
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
Member
Author
|
r? @eddyb |
f0d612f to
03b534c
Compare
Member
Author
|
@eddyb Its ready for review! |
eddyb
suggested changes
Feb 23, 2017
src/librustc_trans/mir/constant.rs
Outdated
| .unwrap().def_id; | ||
| // Now create its substs [Closure, Tuple] | ||
| let input = tcx.closure_type(def_id, substs).sig.input(0); | ||
| let substs = Substs::for_item(tcx, |
Member
There was a problem hiding this comment.
You can just make Substs by doing tcx.mk_substs([operand.ty, input.skip_binder()].iter().cloned()) IIRC.
src/librustc_trans/mir/rvalue.rs
Outdated
| .unwrap().def_id; | ||
| // Now create its substs [Closure, Tuple] | ||
| let input = bcx.tcx().closure_type(def_id, substs).sig.input(0); | ||
| let substs = Substs::for_item(bcx.tcx(), |
|
|
||
| let b = self.shallow_resolve(b); | ||
|
|
||
| let node_id_a :NodeId = self.tcx.hir.as_local_node_id(def_id_a).unwrap(); |
Member
There was a problem hiding this comment.
Type annotations shouldn't be needed.
| let sig = self.closure_type(def_id_a, substs_a).sig; | ||
| let converted_sig = sig.input(0).map_bound(|v| { | ||
| let params_iter = match v.sty { | ||
| TypeVariants::TyTuple(params, _) => { |
| // to | ||
| // `fn(arg0,arg1,...) -> _` | ||
| let sig = self.closure_type(def_id_a, substs_a).sig; | ||
| let converted_sig = sig.input(0).map_bound(|v| { |
Member
There was a problem hiding this comment.
I meant sig.map_bound. Because that lets you avoid skip_binder on output too.
|
|
||
| fn main() { | ||
| let mut a = 0u8; | ||
| let foo :fn(u8) -> u8 = |v: u8| { a += v; a }; |
Member
There was a problem hiding this comment.
let x :T is unidiomatic, should be let x: T.
| assert_eq!({BAR[1](&mut a); a }, 1); | ||
| assert_eq!({BAR[2](&mut a); a }, 3); | ||
| assert_eq!({BAR[3](&mut a); a }, 6); | ||
| assert_eq!({BAR[4](&mut a); a }, 10); |
Member
There was a problem hiding this comment.
{ should be followed by a space just like } should be preceded by one.
* use more convenient mk_substs function * remove type annotations * use map_bound one level farther outside * style improvements
Member
|
@bors r+ |
Collaborator
|
📌 Commit 77f131d has been approved by |
eddyb
approved these changes
Feb 25, 2017
eddyb
added a commit
to eddyb/rust
that referenced
this pull request
Feb 25, 2017
Implement non-capturing closure to fn coercion Implements non capturing closure coercion ([RFC 1558](https://github.com/rust-lang/rfcs/blob/master/text/1558-closure-to-fn-coercion.md)). cc tracking issue rust-lang#39817
eddyb
added a commit
to eddyb/rust
that referenced
this pull request
Feb 25, 2017
Implement non-capturing closure to fn coercion Implements non capturing closure coercion ([RFC 1558](https://github.com/rust-lang/rfcs/blob/master/text/1558-closure-to-fn-coercion.md)). cc tracking issue rust-lang#39817
bors
added a commit
that referenced
this pull request
Feb 25, 2017
Rollup of 28 pull requests - Successful merges: #39859, #39864, #39888, #39903, #39905, #39914, #39945, #39950, #39953, #39961, #39980, #39988, #39993, #39995, #40019, #40020, #40022, #40024, #40025, #40026, #40027, #40031, #40035, #40037, #40038, #40064, #40069, #40086 - Failed merges: #39927, #40008, #40047
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements non capturing closure coercion (RFC 1558).
cc tracking issue #39817