about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2020-10-17 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2020-10-26 10:41:44 +0100
commit52d37826858ee4dad6b66a3060994f41df247770 (patch)
tree2d1bc76c92806acd3d79e0bd8e707657d6daf2f1 /compiler
parente1e48ae29b52d214f93d816e99056aacb102a90a (diff)
downloadrust-52d37826858ee4dad6b66a3060994f41df247770.tar.gz
rust-52d37826858ee4dad6b66a3060994f41df247770.zip
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.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_mir/src/transform/simplify.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_mir/src/transform/simplify.rs b/compiler/rustc_mir/src/transform/simplify.rs
index f88156588e5..183111877d1 100644
--- a/compiler/rustc_mir/src/transform/simplify.rs
+++ b/compiler/rustc_mir/src/transform/simplify.rs
@@ -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,
                 };