simplify-locals: Remove unused set-discriminant statements
Update affected ui & incremental tests to use a user declared variable bindings instead of temporaries. The former are preserved because of debuginfo, the latter are not.
This commit is contained in:
@@ -427,7 +427,6 @@ impl Visitor<'_> for UsedLocals {
|
||||
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
|
||||
match statement.kind {
|
||||
StatementKind::LlvmInlineAsm(..)
|
||||
| StatementKind::SetDiscriminant { .. } // FIXME: Try to remove those as well.
|
||||
| StatementKind::Retag(..)
|
||||
| StatementKind::Coverage(..)
|
||||
| StatementKind::FakeRead(..)
|
||||
@@ -467,6 +466,10 @@ impl Visitor<'_> for UsedLocals {
|
||||
}
|
||||
self.visit_rvalue(rvalue, location);
|
||||
}
|
||||
|
||||
StatementKind::SetDiscriminant { ref place, variant_index: _ } => {
|
||||
self.visit_lhs(place, location);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -481,10 +484,7 @@ impl Visitor<'_> for UsedLocals {
|
||||
}
|
||||
|
||||
/// Removes unused definitions. Updates the used locals to reflect the changes made.
|
||||
fn remove_unused_definitions<'a, 'tcx>(
|
||||
used_locals: &'a mut UsedLocals,
|
||||
body: &mut Body<'tcx>,
|
||||
) {
|
||||
fn remove_unused_definitions<'a, 'tcx>(used_locals: &'a mut UsedLocals, body: &mut Body<'tcx>) {
|
||||
// The use counts are updated as we remove the statements. A local might become unused
|
||||
// during the retain operation, leading to a temporary inconsistency (storage statements or
|
||||
// definitions referencing the local might remain). For correctness it is crucial that this
|
||||
@@ -502,6 +502,10 @@ fn remove_unused_definitions<'a, 'tcx>(
|
||||
used_locals.is_used(*local)
|
||||
}
|
||||
StatementKind::Assign(box (place, _)) => used_locals.is_used(place.local),
|
||||
|
||||
StatementKind::SetDiscriminant { ref place, .. } => {
|
||||
used_locals.is_used(place.local)
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user