Skip to content

Commit 8e24091

Browse files
committed
Factor inc/dec count methods.
1 parent 7516759 commit 8e24091

File tree

3 files changed

+30
-9
lines changed

3 files changed

+30
-9
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
928928
self.unresolved_imports += 1;
929929

930930
if is_public {
931-
module_.pub_count.set(module_.pub_count.get() + 1);
931+
module_.inc_pub_count();
932932
}
933933

934934
// Bump the reference count on the name. Or, if this is a glob, set
@@ -963,9 +963,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
963963
// Set the glob flag. This tells us that we don't know the
964964
// module's exports ahead of time.
965965

966-
module_.glob_count.set(module_.glob_count.get() + 1);
966+
module_.inc_glob_count();
967967
if is_public {
968-
module_.pub_glob_count.set(module_.pub_glob_count.get() + 1);
968+
module_.inc_pub_glob_count();
969969
}
970970
}
971971
}

src/librustc_resolve/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,30 @@ impl Module {
749749
}
750750
}
751751

752+
impl Module {
753+
pub fn inc_glob_count(&self) {
754+
self.glob_count.set(self.glob_count.get() + 1);
755+
}
756+
pub fn dec_glob_count(&self) {
757+
assert!(self.glob_count.get() > 0);
758+
self.glob_count.set(self.glob_count.get() - 1);
759+
}
760+
pub fn inc_pub_count(&self) {
761+
self.pub_count.set(self.pub_count.get() + 1);
762+
}
763+
pub fn dec_pub_count(&self) {
764+
assert!(self.pub_count.get() > 0);
765+
self.pub_count.set(self.pub_count.get() - 1);
766+
}
767+
pub fn inc_pub_glob_count(&self) {
768+
self.pub_glob_count.set(self.pub_glob_count.get() + 1);
769+
}
770+
pub fn dec_pub_glob_count(&self) {
771+
assert!(self.pub_glob_count.get() > 0);
772+
self.pub_glob_count.set(self.pub_glob_count.get() - 1);
773+
}
774+
}
775+
752776
impl fmt::Debug for Module {
753777
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
754778
write!(f, "{:?}, kind: {:?}, {}",

src/librustc_resolve/resolve_imports.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -407,20 +407,17 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
407407
if resolution_result.success() {
408408
match import_directive.subclass {
409409
GlobImport => {
410-
assert!(module_.glob_count.get() >= 1);
411-
module_.glob_count.set(module_.glob_count.get() - 1);
410+
module_.dec_glob_count();
412411
if import_directive.is_public {
413-
assert!(module_.pub_glob_count.get() >= 1);
414-
module_.pub_glob_count.set(module_.pub_glob_count.get() - 1);
412+
module_.dec_pub_glob_count();
415413
}
416414
}
417415
SingleImport(..) => {
418416
// Ignore.
419417
}
420418
}
421419
if import_directive.is_public {
422-
assert!(module_.pub_count.get() >= 1);
423-
module_.pub_count.set(module_.pub_count.get() - 1);
420+
module_.dec_pub_count();
424421
}
425422
}
426423

0 commit comments

Comments
 (0)