Implement for<> lifetime binder for closures#98705
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @oli-obk (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
cc @cjgillot even without an impl in ast_lowering, shouldn't this get picked up since you've moved name resolution earlier? Or is that still WIP?
|
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
fd56fff to
c68cd2f
Compare
This comment has been minimized.
This comment has been minimized.
|
Omg, I just noticed // `Expr` is used a lot. Make sure it doesn't unintentionally get bigger.
#[cfg(all(target_arch = "x86_64", target_pointer_width = "64"))]
//rustc_data_structures::static_assert_size!(Expr, 104); // FIXME
impl Expr {the cfg applies to the impl block now |
This comment has been minimized.
This comment has been minimized.
|
@WaffleLapkin when you get a chance could you add a formatting test case for bound closure to |
cjgillot
left a comment
There was a problem hiding this comment.
Thanks @WaffleLapkin. I left a few comments.
compiler/rustc_hir/src/hir.rs
Outdated
There was a problem hiding this comment.
This field also holds generic parameters introduced by lifetime resolution. Can this and binder be merged?
There was a problem hiding this comment.
This would require to distinguish somewhere the presence of the for<> in code vs just in HIR.
There was a problem hiding this comment.
Honestly, I'm not sure. This can probably be binder: ClosureBinder { Present, NotPresent } and all lifetimes stored in bound_generic_params, but this makes it impossible to distinguish lifetimes from binder from other lifetimes... No idea if we really need to distinguish them though
There was a problem hiding this comment.
bound_generic_params is only filled by anonymous lifetimes, that you explicitly ban. So I don't think you need to worry about separating both.
Furthermore, if we ever allow anonymous lifetimes with a for<>, we will want them to use the for<> semantics and not the default/legacy one, won't we?
There was a problem hiding this comment.
So I've tried this in 27905df77fd6dd9ad6d73b7820ff3d020ec2e7b3 and... in my humble opinion the code turned out to be worse.
There was a problem hiding this comment.
Could you merge this arm with the previous one?
There was a problem hiding this comment.
No, it doesn't have a trailing space.
There was a problem hiding this comment.
Why do you want to skip the trailing whitespace? I couldn't find a ui test suggesting to introduce a closure for bound.
There was a problem hiding this comment.
Because we only suggest for<'lifetime> when there is already for<>. So we suggest replacing for<> with for<'lifetime>. In cases of BoundEmpty and TypeEmpty this is used when there is no for<> at all, so in these cases it makes sense to add a trailing space.
However at closer inspection... I don't think this is ever used. This variant is added to missing_named_lifetime_spots which is used only in add_missing_lifetime_specifiers_label that is only used in resolve_elided_lifetimes which, IIRC, is not called for closures.
There was a problem hiding this comment.
Ok. I'll see what I will do when moving this diagnostic to AST resolution.
There was a problem hiding this comment.
cc @eddyb is that ok to replace recovering with parsing closures?
|
☔ The latest upstream changes (presumably #98584) made this pull request unmergeable. Please resolve the merge conflicts. |
b8b1efd to
bc608ac
Compare
|
I think this is ready for the next round of review @rustbot ready |
cjgillot
left a comment
There was a problem hiding this comment.
Thanks @WaffleLapkin. I think this looks very good. AFAICT, there is just your 2 FIXMEs to handle.
compiler/rustc_hir/src/hir.rs
Outdated
There was a problem hiding this comment.
Likewise, should we box the Closure variant?
There was a problem hiding this comment.
Like so
// ExprKind
Closure(&'hir Closure<'hir>),struct Closure<'hir> {
binder: &'hir ClosureBinder,
capture_clause: CaptureBy,
bound_generic_params: &'hir [GenericParam<'hir>],
fn_decl: &'hir FnDecl<'hir>,
body: BodyId,
fn_decl_span: Span,
movability: Option<Movability>,
}?
Maybe, I'm not sure.
|
Some changes occurred in need_type_info.rs cc @lcnr |
This comment has been minimized.
This comment has been minimized.
This helps bring `hir::Expr` size down, `Closure` was the biggest variant, especially after `for<>` additions.
c7b33a3 to
9aa142b
Compare
|
@bors r=cjgillot |
|
@WaffleLapkin: 🔑 Insufficient privileges: Not in reviewers |
|
@bors r+ |
…llot Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](rust-lang#97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc `@Aaron1011` `@cjgillot`
Rollup of 5 pull requests Successful merges: - rust-lang#97720 (Always create elided lifetime parameters for functions) - rust-lang#98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`) - rust-lang#98705 (Implement `for<>` lifetime binder for closures) - rust-lang#99126 (remove allow(rustc::potential_query_instability) in rustc_span) - rust-lang#99139 (Give a better error when `x dist` fails for an optional tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
|
Can someone update the tracking issue now, tick the implementation and link this pr? |
…llot Implement `for<>` lifetime binder for closures This PR implements RFC 3216 ([TI](rust-lang#97362)) and allows code like the following: ```rust let _f = for<'a, 'b> |a: &'a A, b: &'b B| -> &'b C { b.c(a) }; // ^^^^^^^^^^^--- new! ``` cc ``@Aaron1011`` ``@cjgillot``
Rollup of 5 pull requests Successful merges: - rust-lang#97720 (Always create elided lifetime parameters for functions) - rust-lang#98315 (Stabilize `core::ffi:c_*` and rexport in `std::ffi`) - rust-lang#98705 (Implement `for<>` lifetime binder for closures) - rust-lang#99126 (remove allow(rustc::potential_query_instability) in rustc_span) - rust-lang#99139 (Give a better error when `x dist` fails for an optional tool) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This PR implements RFC 3216 (TI) and allows code like the following:
cc @Aaron1011 @cjgillot