about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-03-13 09:59:16 +0000
committerJeffrey Seyfried <jeffrey.seyfried@gmail.com>2016-03-13 10:45:08 +0000
commitfa18403a2f4acf203964c2ea7c8660752ee99cc3 (patch)
treec029334bc42d9ea22cd04aee753d7d27bcb42531 /src
parent3e05371c13f851a5af57a96a5e13c99537787314 (diff)
downloadrust-fa18403a2f4acf203964c2ea7c8660752ee99cc3.tar.gz
rust-fa18403a2f4acf203964c2ea7c8660752ee99cc3.zip
Refactor out methods `NameResolution::increment_outstanding_references` and
`NameResolution::decrement_outstanding_references`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_resolve/resolve_imports.rs37
1 files changed, 22 insertions, 15 deletions
diff --git a/src/librustc_resolve/resolve_imports.rs b/src/librustc_resolve/resolve_imports.rs
index ea16211c40d..89586db32bc 100644
--- a/src/librustc_resolve/resolve_imports.rs
+++ b/src/librustc_resolve/resolve_imports.rs
@@ -176,6 +176,25 @@ impl<'a> NameResolution<'a> {
         }
     }
 
+    fn increment_outstanding_references(&mut self, is_public: bool) {
+        self.outstanding_references += 1;
+        if is_public {
+            self.pub_outstanding_references += 1;
+        }
+    }
+
+    fn decrement_outstanding_references(&mut self, is_public: bool) {
+        let decrement_references = |count: &mut _| {
+            assert!(*count > 0);
+            *count -= 1;
+        };
+
+        decrement_references(&mut self.outstanding_references);
+        if is_public {
+            decrement_references(&mut self.pub_outstanding_references);
+        }
+    }
+
     fn report_conflicts<F: FnMut(&NameBinding, &NameBinding)>(&self, mut report: F) {
         let binding = match self.binding {
             Some(binding) => binding,
@@ -253,25 +272,13 @@ impl<'a> ::ModuleS<'a> {
     }
 
     pub fn increment_outstanding_references_for(&self, name: Name, ns: Namespace, is_public: bool) {
-        let mut resolutions = self.resolutions.borrow_mut();
-        let resolution = resolutions.entry((name, ns)).or_insert_with(Default::default);
-        resolution.outstanding_references += 1;
-        if is_public {
-            resolution.pub_outstanding_references += 1;
-        }
+        self.resolutions.borrow_mut().entry((name, ns)).or_insert_with(Default::default)
+            .increment_outstanding_references(is_public);
     }
 
     fn decrement_outstanding_references_for(&self, name: Name, ns: Namespace, is_public: bool) {
-        let decrement_references = |count: &mut _| {
-            assert!(*count > 0);
-            *count -= 1;
-        };
-
         self.update_resolution(name, ns, |resolution| {
-            decrement_references(&mut resolution.outstanding_references);
-            if is_public {
-                decrement_references(&mut resolution.pub_outstanding_references);
-            }
+            resolution.decrement_outstanding_references(is_public);
         })
     }