-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Always record reference to binding in match if guards #78393
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -344,6 +344,18 @@ impl<'a, 'tcx> Visitor<'tcx> for InteriorVisitor<'a, 'tcx> { | |
// The type table might not have information for this expression | ||
// if it is in a malformed scope. (#66387) | ||
if let Some(ty) = self.fcx.typeck_results.borrow().expr_ty_opt(expr) { | ||
if guard_borrowing_from_pattern { | ||
// Match guards create references to all the bindings in the pattern that are used | ||
// in the guard, e.g. `y if is_even(y) => ...` becomes `is_even(*r_y)` where `r_y` | ||
// is a reference to `y`, so we must record a reference to the type of the binding. | ||
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), | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. I think this is the only call to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
self.record(ty, scope, Some(expr), expr.span, guard_borrowing_from_pattern); | ||
} else { | ||
self.fcx.tcx.sess.delay_span_bug(expr.span, "no type for node"); | ||
|
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.