-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix region issues when using inline const block #88018
Conversation
tcx.fold_regions(ty, &mut false, |r, _| match r { | ||
ty::ReErased => tcx.lifetimes.re_static, | ||
_ => r, | ||
}) |
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.
This doesn't seem right... once we erased regions, we shouldn't un-erase them. This can go wrong way too easily.
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.
The code above gets the type from tcx.typeck(def_id).node_type(hir_id)
. The type retrieved has their lifetimes erased by rustc_typeck::check::writeback
already.
I believe there is an underlying issue and this PR treats the symptoms. We should look into addressing the underlying issue. The ICE occurs in
In rust/compiler/rustc_mir/src/borrow_check/universal_regions.rs Lines 422 to 433 in 4fdac23
We need something similar for anon consts. The reason we can't just throw around static lifetimes is that you may have types like |
the underlying issue here should also get fixed by typechecking inline consts together with their parent, see https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/inline.20consts.20typeck this will cause us to modify |
The direct cause is
type_of in turn retrieves type with tcx.typeck(def_id).node_type(hir_id) which gives a Ty with lifetime erased.
The example you give currently doesn't work since inline consts are not typechecked with the enclosing body, so inference wouldn't work across I do think the |
I don't think un-erasing is a reasonable fix even short-term -- the risk of unsoundness just seems too high to me. The rest of the changes I have no strong opinion on. |
But aren't these erasings unnecessary long term? Lifetimes will get erased during mir borrowck anyway. I am not comfortable merging this PR as it does things that will ultimately need to be undone in order to start on a fix and conveys a wrong sense of "it works" to users of the feature gate. |
rust/compiler/rustc_mir_build/src/build/mod.rs Lines 223 to 234 in 4fdac23
The MIR builder has assertions here which complains if there are any regions. We can either
I prefer the first option since the assertion could catch other cases where lifetime shouldn't slip through, and it'll ensure code handling MIR wouldn't have to deal with non-erased regions. |
why haven't we hit that assertion before? The assertion from the issues happens in mir borrowck, so we do get that far |
Because currently |
Right, but if we don't do your change which replaces erased regions with static regions, it will keep doing that, making all the region erasing code you wrote a no-op. What I'm trying to say is that we should not do changes that don't change anything except add more code that the next person looking at this will try to understand the reason for and fail, because there is no reason (at the moment). Yes anon consts are buggy and do wrong things, but I don't think we should proactively try to patch stuff to prepare for changes that no one is currently actively working on. |
@rustbot modify labels -S-waiting-on-review +S-blocked |
☔ The latest upstream changes (presumably #88088) made this pull request unmergeable. Please resolve the merge conflicts. |
Superseded by #89561 |
Fixes #78174
Fixes #81857
r? @oli-obk