@@ -425,13 +425,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
425425 /// Resolves all imports for the crate. This method performs the fixed-
426426 /// point iteration.
427427 pub ( crate ) fn resolve_imports ( & mut self ) {
428- let mut prev_num_indeterminates = self . indeterminate_imports . len ( ) + 1 ;
429- while self . indeterminate_imports . len ( ) < prev_num_indeterminates {
430- prev_num_indeterminates = self . indeterminate_imports . len ( ) ;
428+ let mut prev_indeterminate_count = usize:: MAX ;
429+ let mut indeterminate_count = self . indeterminate_imports . len ( ) * 3 ;
430+ while indeterminate_count < prev_indeterminate_count {
431+ prev_indeterminate_count = indeterminate_count;
432+ indeterminate_count = 0 ;
431433 for import in mem:: take ( & mut self . indeterminate_imports ) {
432- match self . resolve_import ( & import) {
433- true => self . determined_imports . push ( import) ,
434- false => self . indeterminate_imports . push ( import) ,
434+ let import_indeterminate_count = self . resolve_import ( & import) ;
435+ indeterminate_count += import_indeterminate_count;
436+ match import_indeterminate_count {
437+ 0 => self . determined_imports . push ( import) ,
438+ _ => self . indeterminate_imports . push ( import) ,
435439 }
436440 }
437441 }
@@ -611,9 +615,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
611615 diag. emit ( ) ;
612616 }
613617
614- /// Attempts to resolve the given import, returning true if its resolution is determined.
615- /// If successful, the resolved bindings are written into the module.
616- fn resolve_import ( & mut self , import : & ' a Import < ' a > ) -> bool {
618+ /// Attempts to resolve the given import, returning:
619+ /// - `0` means its resolution is determined.
620+ /// - Other values mean that indeterminate exists under certain namespaces.
621+ ///
622+ /// Meanwhile, if resolve successful, the resolved bindings are written
623+ /// into the module.
624+ fn resolve_import ( & mut self , import : & ' a Import < ' a > ) -> usize {
617625 debug ! (
618626 "(resolving import for module) resolving import `{}::...` in `{}`" ,
619627 Segment :: names_to_string( & import. module_path) ,
@@ -631,8 +639,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
631639
632640 match path_res {
633641 PathResult :: Module ( module) => module,
634- PathResult :: Indeterminate => return false ,
635- PathResult :: NonModule ( ..) | PathResult :: Failed { .. } => return true ,
642+ PathResult :: Indeterminate => return 3 ,
643+ PathResult :: NonModule ( ..) | PathResult :: Failed { .. } => return 0 ,
636644 }
637645 } ;
638646
@@ -648,12 +656,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
648656 } => ( source, target, source_bindings, target_bindings, type_ns_only) ,
649657 ImportKind :: Glob { .. } => {
650658 self . resolve_glob_import ( import) ;
651- return true ;
659+ return 0 ;
652660 }
653661 _ => unreachable ! ( ) ,
654662 } ;
655663
656- let mut indeterminate = false ;
664+ let mut indeterminate_count = 0 ;
657665 self . per_ns ( |this, ns| {
658666 if !type_ns_only || ns == TypeNS {
659667 if let Err ( Undetermined ) = source_bindings[ ns] . get ( ) {
@@ -676,7 +684,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
676684
677685 let parent = import. parent_scope . module ;
678686 match source_bindings[ ns] . get ( ) {
679- Err ( Undetermined ) => indeterminate = true ,
687+ Err ( Undetermined ) => indeterminate_count += 1 ,
680688 // Don't update the resolution, because it was never added.
681689 Err ( Determined ) if target. name == kw:: Underscore => { }
682690 Ok ( binding) if binding. is_importable ( ) => {
@@ -700,7 +708,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
700708 }
701709 } ) ;
702710
703- !indeterminate
711+ indeterminate_count
704712 }
705713
706714 /// Performs final import resolution, consistency checks and error reporting.
0 commit comments