]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/borrow_check/used_muts.rs
Remove PlaceBase enum and make Place base field be local: Local
[rust.git] / src / librustc_mir / borrow_check / used_muts.rs
index 695080dfe23d90e2e41b0d7ef870b576d3e17930..5e4eebb771f21d8a6cf5e26fac8cbeed481f9e49 100644 (file)
@@ -1,7 +1,5 @@
 use rustc::mir::visit::{PlaceContext, Visitor};
-use rustc::mir::{
-    Local, Location, Place, PlaceBase, Statement, StatementKind, TerminatorKind
-};
+use rustc::mir::{Local, Location, Place, Statement, StatementKind, TerminatorKind};
 
 use rustc_data_structures::fx::FxHashSet;
 
@@ -59,56 +57,39 @@ fn remove_never_initialized_mut_locals(&mut self, into: &Place<'_>) {
         // be those that were never initialized - we will consider those as being used as
         // they will either have been removed by unreachable code optimizations; or linted
         // as unused variables.
-        if let PlaceBase::Local(local) = into.base {
-            let _ = self.never_initialized_mut_locals.remove(&local);
-        }
+        self.never_initialized_mut_locals.remove(&into.local);
     }
 }
 
 impl<'visit, 'cx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'tcx> {
-    fn visit_terminator_kind(
-        &mut self,
-        kind: &TerminatorKind<'tcx>,
-        _location: Location,
-    ) {
+    fn visit_terminator_kind(&mut self, kind: &TerminatorKind<'tcx>, _location: Location) {
         debug!("visit_terminator_kind: kind={:?}", kind);
         match &kind {
             TerminatorKind::Call { destination: Some((into, _)), .. } => {
                 self.remove_never_initialized_mut_locals(&into);
-            },
+            }
             TerminatorKind::DropAndReplace { location, .. } => {
                 self.remove_never_initialized_mut_locals(&location);
-            },
-            _ => {},
+            }
+            _ => {}
         }
     }
 
-    fn visit_statement(
-        &mut self,
-        statement: &Statement<'tcx>,
-        _location: Location,
-    ) {
+    fn visit_statement(&mut self, statement: &Statement<'tcx>, _location: Location) {
         match &statement.kind {
-            StatementKind::Assign(box(into, _)) => {
-                if let PlaceBase::Local(local) = into.base {
-                    debug!(
-                        "visit_statement: statement={:?} local={:?} \
-                         never_initialized_mut_locals={:?}",
-                        statement, local, self.never_initialized_mut_locals
-                    );
-                }
+            StatementKind::Assign(box (into, _)) => {
+                debug!(
+                    "visit_statement: statement={:?} local={:?} \
+                    never_initialized_mut_locals={:?}",
+                    statement, into.local, self.never_initialized_mut_locals
+                );
                 self.remove_never_initialized_mut_locals(into);
-            },
-            _ => {},
+            }
+            _ => {}
         }
     }
 
-    fn visit_local(
-        &mut self,
-        local: &Local,
-        place_context: PlaceContext,
-        location: Location,
-    ) {
+    fn visit_local(&mut self, local: &Local, place_context: PlaceContext, location: Location) {
         if place_context.is_place_assignment() && self.temporary_used_locals.contains(local) {
             // Propagate the Local assigned at this Location as a used mutable local variable
             for moi in &self.mbcx.move_data.loc_map[location] {
@@ -118,10 +99,7 @@ fn visit_local(
                     "assignment of {:?} to {:?}, adding {:?} to used mutable set",
                     path.place, local, path.place
                 );
-                if let Place {
-                    base: PlaceBase::Local(user_local),
-                    projection: box [],
-                } = path.place {
+                if let Some(user_local) = path.place.as_local() {
                     self.mbcx.used_mut.insert(user_local);
                 }
             }