@@ -71,7 +71,7 @@ pub enum ImportDirectiveSubclass<'a> {
71
71
}
72
72
73
73
/// One import directive.
74
- #[ derive( Debug , Clone ) ]
74
+ #[ derive( Debug , Clone ) ]
75
75
crate struct ImportDirective < ' a > {
76
76
/// The ID of the `extern crate`, `UseTree` etc that imported this `ImportDirective`.
77
77
///
@@ -447,12 +447,13 @@ impl<'a> Resolver<'a> {
447
447
}
448
448
449
449
// Define the name or return the existing binding if there is a collision.
450
- pub fn try_define ( & mut self ,
451
- module : Module < ' a > ,
452
- ident : Ident ,
453
- ns : Namespace ,
454
- binding : & ' a NameBinding < ' a > )
455
- -> Result < ( ) , & ' a NameBinding < ' a > > {
450
+ pub fn try_define (
451
+ & mut self ,
452
+ module : Module < ' a > ,
453
+ ident : Ident ,
454
+ ns : Namespace ,
455
+ binding : & ' a NameBinding < ' a > ,
456
+ ) -> Result < ( ) , & ' a NameBinding < ' a > > {
456
457
let res = binding. res ( ) ;
457
458
self . check_reserved_macro_name ( ident, res) ;
458
459
self . set_binding_parent_module ( binding, module) ;
@@ -480,8 +481,11 @@ impl<'a> Resolver<'a> {
480
481
} ;
481
482
if glob_binding. res ( ) != nonglob_binding. res ( ) &&
482
483
ns == MacroNS && nonglob_binding. expansion != ExpnId :: root ( ) {
483
- resolution. binding = Some ( this. ambiguity ( AmbiguityKind :: GlobVsExpanded ,
484
- nonglob_binding, glob_binding) ) ;
484
+ resolution. binding = Some ( this. ambiguity (
485
+ AmbiguityKind :: GlobVsExpanded ,
486
+ nonglob_binding,
487
+ glob_binding,
488
+ ) ) ;
485
489
} else {
486
490
resolution. binding = Some ( nonglob_binding) ;
487
491
}
@@ -513,9 +517,11 @@ impl<'a> Resolver<'a> {
513
517
} )
514
518
}
515
519
516
- fn ambiguity ( & self , kind : AmbiguityKind ,
517
- primary_binding : & ' a NameBinding < ' a > , secondary_binding : & ' a NameBinding < ' a > )
518
- -> & ' a NameBinding < ' a > {
520
+ fn ambiguity (
521
+ & self , kind : AmbiguityKind ,
522
+ primary_binding : & ' a NameBinding < ' a > ,
523
+ secondary_binding : & ' a NameBinding < ' a > ,
524
+ ) -> & ' a NameBinding < ' a > {
519
525
self . arenas . alloc_name_binding ( NameBinding {
520
526
ambiguity : Some ( ( secondary_binding, kind) ) ,
521
527
..primary_binding. clone ( )
@@ -524,8 +530,12 @@ impl<'a> Resolver<'a> {
524
530
525
531
// Use `f` to mutate the resolution of the name in the module.
526
532
// If the resolution becomes a success, define it in the module's glob importers.
527
- fn update_resolution < T , F > ( & mut self , module : Module < ' a > , ident : Ident , ns : Namespace , f : F )
528
- -> T
533
+ fn update_resolution < T , F > (
534
+ & mut self , module : Module < ' a > ,
535
+ ident : Ident ,
536
+ ns : Namespace ,
537
+ f : F ,
538
+ ) -> T
529
539
where F : FnOnce ( & mut Resolver < ' a > , & mut NameResolution < ' a > ) -> T
530
540
{
531
541
// Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
@@ -627,14 +637,18 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
627
637
self . finalize_resolutions_in ( module) ;
628
638
}
629
639
630
- let mut has_errors = false ;
631
640
let mut seen_spans = FxHashSet :: default ( ) ;
632
641
let mut errors = vec ! [ ] ;
633
642
let mut prev_root_id: NodeId = NodeId :: from_u32 ( 0 ) ;
634
- for i in 0 .. self . r . determined_imports . len ( ) {
635
- let import = self . r . determined_imports [ i] ;
643
+ let determined_imports = mem:: take ( & mut self . r . determined_imports ) ;
644
+ let indeterminate_imports = mem:: take ( & mut self . r . indeterminate_imports ) ;
645
+
646
+ for ( is_indeterminate, import) in determined_imports
647
+ . into_iter ( )
648
+ . map ( |i| ( false , i) )
649
+ . chain ( indeterminate_imports. into_iter ( ) . map ( |i| ( true , i) ) )
650
+ {
636
651
if let Some ( err) = self . finalize_import ( import) {
637
- has_errors = true ;
638
652
639
653
if let SingleImport { source, ref source_bindings, .. } = import. subclass {
640
654
if source. name == kw:: SelfLower {
@@ -666,25 +680,27 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
666
680
errors. push ( ( path, err) ) ;
667
681
prev_root_id = import. root_id ;
668
682
}
683
+ } else if is_indeterminate {
684
+ // Consider erroneous imports used to avoid duplicate diagnostics.
685
+ self . r . used_imports . insert ( ( import. id , TypeNS ) ) ;
686
+ let path = import_path_to_string (
687
+ & import. module_path . iter ( ) . map ( |seg| seg. ident ) . collect :: < Vec < _ > > ( ) ,
688
+ & import. subclass ,
689
+ import. span ,
690
+ ) ;
691
+ let err = UnresolvedImportError {
692
+ span : import. span ,
693
+ label : None ,
694
+ note : Vec :: new ( ) ,
695
+ suggestion : None ,
696
+ } ;
697
+ errors. push ( ( path, err) ) ;
669
698
}
670
699
}
671
700
672
701
if !errors. is_empty ( ) {
673
702
self . throw_unresolved_import_error ( errors. clone ( ) , None ) ;
674
703
}
675
-
676
- for import in & self . r . indeterminate_imports {
677
- // Consider erroneous imports used to avoid duplicate diagnostics.
678
- self . r . used_imports . insert ( ( import. id , TypeNS ) ) ;
679
- }
680
- // Report unresolved imports only if no hard error was already reported
681
- // to avoid generating multiple errors on the same import.
682
- if !has_errors {
683
- for import in & self . r . indeterminate_imports {
684
- self . throw_unresolved_import_error ( errors, Some ( MultiSpan :: from ( import. span ) ) ) ;
685
- break ;
686
- }
687
- }
688
704
}
689
705
690
706
fn throw_unresolved_import_error (
@@ -839,8 +855,14 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
839
855
) -> Option < UnresolvedImportError > {
840
856
let orig_vis = directive. vis . replace ( ty:: Visibility :: Invisible ) ;
841
857
let prev_ambiguity_errors_len = self . r . ambiguity_errors . len ( ) ;
842
- let path_res = self . r . resolve_path ( & directive. module_path , None , & directive. parent_scope ,
843
- true , directive. span , directive. crate_lint ( ) ) ;
858
+ let path_res = self . r . resolve_path (
859
+ & directive. module_path ,
860
+ None ,
861
+ & directive. parent_scope ,
862
+ true ,
863
+ directive. span ,
864
+ directive. crate_lint ( ) ,
865
+ ) ;
844
866
let no_ambiguity = self . r . ambiguity_errors . len ( ) == prev_ambiguity_errors_len;
845
867
directive. vis . set ( orig_vis) ;
846
868
if let PathResult :: Failed { .. } | PathResult :: NonModule ( ..) = path_res {
@@ -903,7 +925,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
903
925
}
904
926
}
905
927
} ;
906
-
907
928
return Some ( err) ;
908
929
}
909
930
return None ;
0 commit comments