-
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
Implement non-capturing closure to fn coercion #40025
Conversation
r? @pnkfelix (rust_highfive has picked a reviewer for you, use r? to override) |
r? @eddyb |
f0d612f
to
03b534c
Compare
@eddyb Its ready for review! |
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, |
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.
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(), |
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.
Same here.
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, _) => { |
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.
ty::TyTuple
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{
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
@bors r+ |
📌 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