@@ -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,26 +272,8 @@ 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- }
262- }
263-
264- 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-
270- 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- }
275- } )
275+ self . resolutions . borrow_mut ( ) . entry ( ( name, ns) ) . or_insert_with ( Default :: default)
276+ . increment_outstanding_references ( is_public) ;
276277 }
277278
278279 // Use `update` to mutate the resolution for the name.
@@ -477,7 +478,8 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
477478 // Temporarily count the directive as determined so that the resolution fails
478479 // (as opposed to being indeterminate) when it can only be defined by the directive.
479480 if !determined {
480- module_. decrement_outstanding_references_for ( target, ns, directive. is_public )
481+ module_. resolutions . borrow_mut ( ) . get_mut ( & ( target, ns) ) . unwrap ( )
482+ . decrement_outstanding_references ( directive. is_public ) ;
481483 }
482484 let result =
483485 self . resolver . resolve_name_in_module ( target_module, source, ns, false , true ) ;
@@ -514,7 +516,10 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
514516 self . report_conflict ( target, ns, & directive. import ( binding, None ) , old_binding) ;
515517 }
516518 }
517- module_. decrement_outstanding_references_for ( target, ns, directive. is_public ) ;
519+
520+ module_. update_resolution ( target, ns, |resolution| {
521+ resolution. decrement_outstanding_references ( directive. is_public ) ;
522+ } )
518523 }
519524
520525 match ( & value_result, & type_result) {
0 commit comments