Skip to content

Commit fa18403

Browse files
committed
Refactor out methods NameResolution::increment_outstanding_references and
`NameResolution::decrement_outstanding_references`.
1 parent 3e05371 commit fa18403

File tree

1 file changed

+22
-15
lines changed

1 file changed

+22
-15
lines changed

src/librustc_resolve/resolve_imports.rs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,25 @@ impl<'a> NameResolution<'a> {
176176
}
177177
}
178178

179+
fn increment_outstanding_references(&mut self, is_public: bool) {
180+
self.outstanding_references += 1;
181+
if is_public {
182+
self.pub_outstanding_references += 1;
183+
}
184+
}
185+
186+
fn decrement_outstanding_references(&mut self, is_public: bool) {
187+
let decrement_references = |count: &mut _| {
188+
assert!(*count > 0);
189+
*count -= 1;
190+
};
191+
192+
decrement_references(&mut self.outstanding_references);
193+
if is_public {
194+
decrement_references(&mut self.pub_outstanding_references);
195+
}
196+
}
197+
179198
fn report_conflicts<F: FnMut(&NameBinding, &NameBinding)>(&self, mut report: F) {
180199
let binding = match self.binding {
181200
Some(binding) => binding,
@@ -253,25 +272,13 @@ impl<'a> ::ModuleS<'a> {
253272
}
254273

255274
pub fn increment_outstanding_references_for(&self, name: Name, ns: Namespace, is_public: bool) {
256-
let mut resolutions = self.resolutions.borrow_mut();
257-
let resolution = resolutions.entry((name, ns)).or_insert_with(Default::default);
258-
resolution.outstanding_references += 1;
259-
if is_public {
260-
resolution.pub_outstanding_references += 1;
261-
}
275+
self.resolutions.borrow_mut().entry((name, ns)).or_insert_with(Default::default)
276+
.increment_outstanding_references(is_public);
262277
}
263278

264279
fn decrement_outstanding_references_for(&self, name: Name, ns: Namespace, is_public: bool) {
265-
let decrement_references = |count: &mut _| {
266-
assert!(*count > 0);
267-
*count -= 1;
268-
};
269-
270280
self.update_resolution(name, ns, |resolution| {
271-
decrement_references(&mut resolution.outstanding_references);
272-
if is_public {
273-
decrement_references(&mut resolution.pub_outstanding_references);
274-
}
281+
resolution.decrement_outstanding_references(is_public);
275282
})
276283
}
277284

0 commit comments

Comments
 (0)