-
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
Always record reference to binding in match if guards #78393
Conversation
r? @lcnr (rust_highfive has picked a reviewer for you, use r? to override) |
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.
seems good to me, but not something I am too familiar with
r? @tmandry maybe |
tcx.mk_region(ty::RegionKind::ReErased), | ||
ty::TypeAndMut { ty, mutbl: hir::Mutability::Not }, | ||
); | ||
self.record(ref_ty, scope, Some(expr), expr.span, guard_borrowing_from_pattern); |
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 think this is the only call to self.record
that actually needs to ever pass true for guard_borrowing_from_pattern
but I didn't want to make the recording of types any less cautious. If there are perf reasons to not want to record too many types in the generator witness we could rethink that.
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.
Hmm, I think you're right. We could try disabling the others in a follow-up.
let tcx = self.fcx.tcx; | ||
let ref_ty = tcx.mk_ref( | ||
// Use `ReErased` as `resolve_interior` is going to replace all the regions anyway. | ||
tcx.mk_region(ty::RegionKind::ReErased), |
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.
Maybe someone with better knowledge about lifetimes in the compiler should double-check this makes sense.
Looks good, thanks for this! @bors r+ By the way, if you're interested in helping out more, I'd be delighted if you came by the wg-async-foundations stream on Zulip. |
📌 Commit 8bf9abb has been approved by |
☀️ Test successful - checks-actions |
When encountering a binding from a
match
pattern in itsif
guard when computing a generator's interior types, we must always record the type of a reference to the binding because of howif
guards are lowered to MIR. This was missed in #75213 because the binding in that test case was autorefed and we recorded that adjusted type anyway.Fixes #78366