about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2024-10-11 17:07:13 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2024-11-04 17:36:25 +1100
commitce2f0b4ce9bb34ca22251317ce66c71c1a2df26a (patch)
tree90217d760f1955321094d2ff725caeeea96e5e7a /compiler/rustc_borrowck/src
parent6ecf80e1ad38198ce49f0d908283319345a80ed2 (diff)
downloadrust-ce2f0b4ce9bb34ca22251317ce66c71c1a2df26a.tar.gz
rust-ce2f0b4ce9bb34ca22251317ce66c71c1a2df26a.zip
Simplify `LocalUseMapBuild`.
It has four different `insert` methods, with some duplication. This
commit finds the commonality and removes them all.
Diffstat (limited to 'compiler/rustc_borrowck/src')
-rw-r--r--compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs62
1 files changed, 14 insertions, 48 deletions
diff --git a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs
index ccd9fb25739..695a1cdac0d 100644
--- a/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs
+++ b/compiler/rustc_borrowck/src/type_check/liveness/local_use_map.rs
@@ -137,56 +137,22 @@ struct LocalUseMapBuild<'me> {
     locals_with_use_data: IndexVec<Local, bool>,
 }
 
-impl LocalUseMapBuild<'_> {
-    fn insert_def(&mut self, local: Local, location: Location) {
-        Self::insert(
-            self.elements,
-            &mut self.local_use_map.first_def_at[local],
-            &mut self.local_use_map.appearances,
-            location,
-        );
-    }
-
-    fn insert_use(&mut self, local: Local, location: Location) {
-        Self::insert(
-            self.elements,
-            &mut self.local_use_map.first_use_at[local],
-            &mut self.local_use_map.appearances,
-            location,
-        );
-    }
-
-    fn insert_drop(&mut self, local: Local, location: Location) {
-        Self::insert(
-            self.elements,
-            &mut self.local_use_map.first_drop_at[local],
-            &mut self.local_use_map.appearances,
-            location,
-        );
-    }
-
-    fn insert(
-        elements: &DenseLocationMap,
-        first_appearance: &mut Option<AppearanceIndex>,
-        appearances: &mut Appearances,
-        location: Location,
-    ) {
-        let point_index = elements.point_from_location(location);
-        let appearance_index =
-            appearances.push(Appearance { point_index, next: *first_appearance });
-        *first_appearance = Some(appearance_index);
-    }
-}
-
 impl Visitor<'_> for LocalUseMapBuild<'_> {
     fn visit_local(&mut self, local: Local, context: PlaceContext, location: Location) {
-        if self.locals_with_use_data[local] {
-            match def_use::categorize(context) {
-                Some(DefUse::Def) => self.insert_def(local, location),
-                Some(DefUse::Use) => self.insert_use(local, location),
-                Some(DefUse::Drop) => self.insert_drop(local, location),
-                _ => (),
-            }
+        if self.locals_with_use_data[local]
+            && let Some(def_use) = def_use::categorize(context)
+        {
+            let first_appearance = match def_use {
+                DefUse::Def => &mut self.local_use_map.first_def_at[local],
+                DefUse::Use => &mut self.local_use_map.first_use_at[local],
+                DefUse::Drop => &mut self.local_use_map.first_drop_at[local],
+            };
+            let point_index = self.elements.point_from_location(location);
+            let appearance_index = self
+                .local_use_map
+                .appearances
+                .push(Appearance { point_index, next: *first_appearance });
+            *first_appearance = Some(appearance_index);
         }
     }
 }