Fix ICE when late-bound lifetimes don't appear in fn signature#147631
Fix ICE when late-bound lifetimes don't appear in fn signature#147631JohnTitor wants to merge 1 commit intorust-lang:mainfrom
Conversation
PR rust-lang#135479 changed how late-bound regions are registered for MIR borrowck, switching from `for_each_late_bound_region_in_item` to iterating over `bound_inputs_and_output.bound_vars()`. However, for regular functions, the latter only includes late-bound lifetimes that appear in the function's inputs or output, missing unused lifetime parameters. This caused an ICE when `replace_bound_regions_with_nll_infer_vars` tried to look up these unregistered regions. This ensures all late-bound regions are properly registered in the universal regions map before they're needed during region substitution.
|
This PR changes a file inside |
|
r? @davidtwco rustbot has assigned @davidtwco. Use |
|
|
r? types |
| | DefiningTy::Coroutine(..) | ||
| | DefiningTy::CoroutineClosure(..) => { | ||
| // For closures/coroutines, iterate over bound_vars to include implicit regions. | ||
| for (idx, bound_var) in bound_inputs_and_output.bound_vars().iter().enumerate() { |
There was a problem hiding this comment.
Hmm, so. This seems incompatible with the closure_lifetime_binder feature?
I think we should get @lcnr's thoughts on this, on why this switch was made (and if it's appropriate to go back to calling for_each_late_bound_region_in_item on everything).
That doesn't seem to be quite true 🤔 from what I can tell all the ICE happen in cases where the fn-sig is malformed. The following compiles: struct S<'a, T: ?Sized>(&'a T);
fn b<'a>() -> S<'static, u32> {
S::<'a>(&0)
}
I would also expect the same to be true for closures. The #![feature(closure_lifetime_binder)]
struct S<'a, T: ?Sized>(&'a T);
fn b() {
for<'a> || -> S<'static, u32> {
S::<'a>(&0)
};
}I personally believe the bug here to be that we don't include late bound regions in the binder if there's an error. We could even add an assert in |
Iirc the main reason behind #135479 was that previously we lazily converted bound regions which feels questionable to me. I switched us to first add nll vars for every late-bound region, and then convert as normal, without having to optionally create new bound regions |
Okay, yes, that's actually what I would expect too! But wasn't quite sure. |
|
☔ The latest upstream changes (presumably #149535) made this pull request unmergeable. Please resolve the merge conflicts. |
Fix ICE in borrowck when recovering `fn_sig` for `-> _` (Should be) a proper fix for rust-lang#135845, replaces a dummy binder with a concrete one not to ICE, as mentioned in rust-lang#147631 (comment). Fixes rust-lang#135845 r? @lcnr @jackh726
Fix ICE in borrowck when recovering `fn_sig` for `-> _` (Should be) a proper fix for rust-lang#135845, replaces a dummy binder with a concrete one not to ICE, as mentioned in rust-lang#147631 (comment). Fixes rust-lang#135845 r? @lcnr @jackh726
Fix ICE in borrowck when recovering `fn_sig` for `-> _` (Should be) a proper fix for rust-lang#135845, replaces a dummy binder with a concrete one not to ICE, as mentioned in rust-lang#147631 (comment). Fixes rust-lang#135845 r? @lcnr @jackh726
Fix ICE in borrowck when recovering `fn_sig` for `-> _` (Should be) a proper fix for rust-lang#135845, replaces a dummy binder with a concrete one not to ICE, as mentioned in rust-lang#147631 (comment). Fixes rust-lang#135845 r? @lcnr @jackh726
PR #135479 changed how late-bound regions are registered for MIR borrowck, switching from
for_each_late_bound_region_in_itemto iterating overbound_inputs_and_output.bound_vars(). However, for regular functions, the latter only includes late-bound lifetimes that appear in the function's inputs or output, missing unused lifetime parameters.This caused an ICE when
replace_bound_regions_with_nll_infer_varstried to look up these unregistered regions.This ensures all late-bound regions are properly registered in the universal regions map before they're needed during region substitution.
Fixes #135845