@@ -425,13 +425,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
425
425
/// Resolves all imports for the crate. This method performs the fixed-
426
426
/// point iteration.
427
427
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 ;
431
433
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) ,
435
439
}
436
440
}
437
441
}
@@ -611,9 +615,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
611
615
diag. emit ( ) ;
612
616
}
613
617
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 {
617
625
debug ! (
618
626
"(resolving import for module) resolving import `{}::...` in `{}`" ,
619
627
Segment :: names_to_string( & import. module_path) ,
@@ -631,8 +639,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
631
639
632
640
match path_res {
633
641
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 ,
636
644
}
637
645
} ;
638
646
@@ -648,12 +656,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
648
656
} => ( source, target, source_bindings, target_bindings, type_ns_only) ,
649
657
ImportKind :: Glob { .. } => {
650
658
self . resolve_glob_import ( import) ;
651
- return true ;
659
+ return 0 ;
652
660
}
653
661
_ => unreachable ! ( ) ,
654
662
} ;
655
663
656
- let mut indeterminate = false ;
664
+ let mut indeterminate_count = 0 ;
657
665
self . per_ns ( |this, ns| {
658
666
if !type_ns_only || ns == TypeNS {
659
667
if let Err ( Undetermined ) = source_bindings[ ns] . get ( ) {
@@ -676,7 +684,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
676
684
677
685
let parent = import. parent_scope . module ;
678
686
match source_bindings[ ns] . get ( ) {
679
- Err ( Undetermined ) => indeterminate = true ,
687
+ Err ( Undetermined ) => indeterminate_count += 1 ,
680
688
// Don't update the resolution, because it was never added.
681
689
Err ( Determined ) if target. name == kw:: Underscore => { }
682
690
Ok ( binding) if binding. is_importable ( ) => {
@@ -700,7 +708,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
700
708
}
701
709
} ) ;
702
710
703
- !indeterminate
711
+ indeterminate_count
704
712
}
705
713
706
714
/// Performs final import resolution, consistency checks and error reporting.
0 commit comments