@@ -423,13 +423,17 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
423
423
/// Resolves all imports for the crate. This method performs the fixed-
424
424
/// point iteration.
425
425
pub ( crate ) fn resolve_imports ( & mut self ) {
426
- let mut prev_num_indeterminates = self . indeterminate_imports . len ( ) + 1 ;
427
- while self . indeterminate_imports . len ( ) < prev_num_indeterminates {
428
- prev_num_indeterminates = self . indeterminate_imports . len ( ) ;
426
+ let mut prev_indeterminate_count = usize:: MAX ;
427
+ let mut indeterminate_count = self . indeterminate_imports . len ( ) * 3 ;
428
+ while indeterminate_count < prev_indeterminate_count {
429
+ prev_indeterminate_count = indeterminate_count;
430
+ indeterminate_count = 0 ;
429
431
for import in mem:: take ( & mut self . indeterminate_imports ) {
430
- match self . resolve_import ( & import) {
431
- true => self . determined_imports . push ( import) ,
432
- false => self . indeterminate_imports . push ( import) ,
432
+ let import_indeterminate_count = self . resolve_import ( & import) ;
433
+ indeterminate_count += import_indeterminate_count;
434
+ match import_indeterminate_count {
435
+ 0 => self . determined_imports . push ( import) ,
436
+ _ => self . indeterminate_imports . push ( import) ,
433
437
}
434
438
}
435
439
}
@@ -581,9 +585,13 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
581
585
diag. emit ( ) ;
582
586
}
583
587
584
- /// Attempts to resolve the given import, returning true if its resolution is determined.
585
- /// If successful, the resolved bindings are written into the module.
586
- fn resolve_import ( & mut self , import : & ' a Import < ' a > ) -> bool {
588
+ /// Attempts to resolve the given import, returning:
589
+ /// - `0` means its resolution is determined.
590
+ /// - Other values mean that indeterminate exists under certain namespaces.
591
+ ///
592
+ /// Meanwhile, if resolve successful, the resolved bindings are written
593
+ /// into the module.
594
+ fn resolve_import ( & mut self , import : & ' a Import < ' a > ) -> usize {
587
595
debug ! (
588
596
"(resolving import for module) resolving import `{}::...` in `{}`" ,
589
597
Segment :: names_to_string( & import. module_path) ,
@@ -601,8 +609,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
601
609
602
610
match path_res {
603
611
PathResult :: Module ( module) => module,
604
- PathResult :: Indeterminate => return false ,
605
- PathResult :: NonModule ( ..) | PathResult :: Failed { .. } => return true ,
612
+ PathResult :: Indeterminate => return 3 ,
613
+ PathResult :: NonModule ( ..) | PathResult :: Failed { .. } => return 0 ,
606
614
}
607
615
} ;
608
616
@@ -618,12 +626,12 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
618
626
} => ( source, target, source_bindings, target_bindings, type_ns_only) ,
619
627
ImportKind :: Glob { .. } => {
620
628
self . resolve_glob_import ( import) ;
621
- return true ;
629
+ return 0 ;
622
630
}
623
631
_ => unreachable ! ( ) ,
624
632
} ;
625
633
626
- let mut indeterminate = false ;
634
+ let mut indeterminate_count = 0 ;
627
635
self . per_ns ( |this, ns| {
628
636
if !type_ns_only || ns == TypeNS {
629
637
if let Err ( Undetermined ) = source_bindings[ ns] . get ( ) {
@@ -646,7 +654,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
646
654
647
655
let parent = import. parent_scope . module ;
648
656
match source_bindings[ ns] . get ( ) {
649
- Err ( Undetermined ) => indeterminate = true ,
657
+ Err ( Undetermined ) => indeterminate_count += 1 ,
650
658
// Don't update the resolution, because it was never added.
651
659
Err ( Determined ) if target. name == kw:: Underscore => { }
652
660
Ok ( binding) if binding. is_importable ( ) => {
@@ -670,7 +678,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
670
678
}
671
679
} ) ;
672
680
673
- !indeterminate
681
+ indeterminate_count
674
682
}
675
683
676
684
/// Performs final import resolution, consistency checks and error reporting.
0 commit comments