]> git.lizzy.rs Git - rust.git/commitdiff
Factor inc/dec count methods.
authorVictor Berger <victor.berger@m4x.org>
Thu, 6 Aug 2015 10:47:10 +0000 (12:47 +0200)
committerVictor Berger <victor.berger@m4x.org>
Thu, 6 Aug 2015 10:47:10 +0000 (12:47 +0200)
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/lib.rs
src/librustc_resolve/resolve_imports.rs

index 355578ddccf2a4c862599cc0f32a09426e57163b..75b99bed431941445b5663525d1af47b1da7612e 100644 (file)
@@ -928,7 +928,7 @@ fn build_import_directive(&mut self,
         self.unresolved_imports += 1;
 
         if is_public {
-            module_.pub_count.set(module_.pub_count.get() + 1);
+            module_.inc_pub_count();
         }
 
         // Bump the reference count on the name. Or, if this is a glob, set
@@ -963,9 +963,9 @@ fn build_import_directive(&mut self,
                 // Set the glob flag. This tells us that we don't know the
                 // module's exports ahead of time.
 
-                module_.glob_count.set(module_.glob_count.get() + 1);
+                module_.inc_glob_count();
                 if is_public {
-                    module_.pub_glob_count.set(module_.pub_glob_count.get() + 1);
+                    module_.inc_pub_glob_count();
                 }
             }
         }
index 1dd26fe7c58afb0f09d42d8652756b727174c4d1..50a8c5885338567702df8494982b93a589e26d30 100644 (file)
@@ -749,6 +749,30 @@ fn all_imports_resolved(&self) -> bool {
     }
 }
 
+impl Module {
+    pub fn inc_glob_count(&self) {
+        self.glob_count.set(self.glob_count.get() + 1);
+    }
+    pub fn dec_glob_count(&self) {
+        assert!(self.glob_count.get() > 0);
+        self.glob_count.set(self.glob_count.get() - 1);
+    }
+    pub fn inc_pub_count(&self) {
+        self.pub_count.set(self.pub_count.get() + 1);
+    }
+    pub fn dec_pub_count(&self) {
+        assert!(self.pub_count.get() > 0);
+        self.pub_count.set(self.pub_count.get() - 1);
+    }
+    pub fn inc_pub_glob_count(&self) {
+        self.pub_glob_count.set(self.pub_glob_count.get() + 1);
+    }
+    pub fn dec_pub_glob_count(&self) {
+        assert!(self.pub_glob_count.get() > 0);
+        self.pub_glob_count.set(self.pub_glob_count.get() - 1);
+    }
+}
+
 impl fmt::Debug for Module {
     fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
         write!(f, "{:?}, kind: {:?}, {}",
index 18fefa967ea3a579f43a6edebea390007076743c..bab9f19bbffd0e87956fe7fad9648c93f1f4d462 100644 (file)
@@ -407,11 +407,9 @@ fn resolve_import_for_module(&mut self,
         if resolution_result.success() {
             match import_directive.subclass {
                 GlobImport => {
-                    assert!(module_.glob_count.get() >= 1);
-                    module_.glob_count.set(module_.glob_count.get() - 1);
+                    module_.dec_glob_count();
                     if import_directive.is_public {
-                        assert!(module_.pub_glob_count.get() >= 1);
-                        module_.pub_glob_count.set(module_.pub_glob_count.get() - 1);
+                        module_.dec_pub_glob_count();
                     }
                 }
                 SingleImport(..) => {
@@ -419,8 +417,7 @@ fn resolve_import_for_module(&mut self,
                 }
             }
             if import_directive.is_public {
-                assert!(module_.pub_count.get() >= 1);
-                module_.pub_count.set(module_.pub_count.get() - 1);
+                module_.dec_pub_count();
             }
         }