Uh oh!
There was an error while loading. Please reload this page.
Implement non-capturing closure to fn coercion - #40025
Conversation
rust-highfive
commented
Feb 22, 2017
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
est31
commented
Feb 22, 2017
r? @eddyb |
f0d612f to
03b534cCompareest31
commented
Feb 23, 2017
@eddyb Its ready for review! |
| .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, |
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.
| .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(); |
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| { |
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 }; |
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); |
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
eddyb
commented
Feb 24, 2017
@bors r+ |
bors
commented
Feb 24, 2017
📌 Commit 77f131d has been approved by |
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
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
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
Implements non capturing closure coercion (RFC 1558).
cc tracking issue #39817