Fix drop handling for if let expressions

MIR lowering for `if let` expressions is now more complicated now that
`if let` exists in HIR. This PR adds a scope for the variables bound in
an `if let` expression and then uses an approach similar to how we
handle loops to ensure that we reliably drop the correct variables.
This commit is contained in:
Matthew Jasper
2021-09-01 22:52:17 +01:00
parent 50171c310c
commit ff8c0ef0e4
56 changed files with 543 additions and 483 deletions

View File

@@ -94,6 +94,7 @@ impl fmt::Debug for Scope {
ScopeData::CallSite => write!(fmt, "CallSite({:?})", self.id),
ScopeData::Arguments => write!(fmt, "Arguments({:?})", self.id),
ScopeData::Destruction => write!(fmt, "Destruction({:?})", self.id),
ScopeData::IfThen => write!(fmt, "IfThen({:?})", self.id),
ScopeData::Remainder(fsi) => write!(
fmt,
"Remainder {{ block: {:?}, first_statement_index: {}}}",
@@ -120,6 +121,10 @@ pub enum ScopeData {
/// Scope of destructors for temporaries of node-id.
Destruction,
/// Scope of the condition and then block of an if expression
/// Used for variables introduced in an if-let expression.
IfThen,
/// Scope following a `let id = expr;` binding in a block.
Remainder(FirstStatementIndex),
}