@@ -71,7 +71,7 @@ pub enum ImportDirectiveSubclass<'a> {
7171}
7272
7373/// One import directive.
74- #[ derive( Debug , Clone ) ]
74+ #[ derive( Debug , Clone ) ]
7575crate struct ImportDirective < ' a > {
7676 /// The ID of the `extern crate`, `UseTree` etc that imported this `ImportDirective`.
7777 ///
@@ -447,12 +447,13 @@ impl<'a> Resolver<'a> {
447447 }
448448
449449 // 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 > > {
456457 let res = binding. res ( ) ;
457458 self . check_reserved_macro_name ( ident, res) ;
458459 self . set_binding_parent_module ( binding, module) ;
@@ -480,8 +481,11 @@ impl<'a> Resolver<'a> {
480481 } ;
481482 if glob_binding. res ( ) != nonglob_binding. res ( ) &&
482483 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+ ) ) ;
485489 } else {
486490 resolution. binding = Some ( nonglob_binding) ;
487491 }
@@ -513,9 +517,11 @@ impl<'a> Resolver<'a> {
513517 } )
514518 }
515519
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 > {
519525 self . arenas . alloc_name_binding ( NameBinding {
520526 ambiguity : Some ( ( secondary_binding, kind) ) ,
521527 ..primary_binding. clone ( )
@@ -524,8 +530,12 @@ impl<'a> Resolver<'a> {
524530
525531 // Use `f` to mutate the resolution of the name in the module.
526532 // 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
529539 where F : FnOnce ( & mut Resolver < ' a > , & mut NameResolution < ' a > ) -> T
530540 {
531541 // Ensure that `resolution` isn't borrowed when defining in the module's glob importers,
@@ -627,14 +637,18 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
627637 self . finalize_resolutions_in ( module) ;
628638 }
629639
630- let mut has_errors = false ;
631640 let mut seen_spans = FxHashSet :: default ( ) ;
632641 let mut errors = vec ! [ ] ;
633642 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+ {
636651 if let Some ( err) = self . finalize_import ( import) {
637- has_errors = true ;
638652
639653 if let SingleImport { source, ref source_bindings, .. } = import. subclass {
640654 if source. name == kw:: SelfLower {
@@ -666,25 +680,27 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
666680 errors. push ( ( path, err) ) ;
667681 prev_root_id = import. root_id ;
668682 }
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) ) ;
669698 }
670699 }
671700
672701 if !errors. is_empty ( ) {
673702 self . throw_unresolved_import_error ( errors. clone ( ) , None ) ;
674703 }
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- }
688704 }
689705
690706 fn throw_unresolved_import_error (
@@ -839,8 +855,14 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
839855 ) -> Option < UnresolvedImportError > {
840856 let orig_vis = directive. vis . replace ( ty:: Visibility :: Invisible ) ;
841857 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+ ) ;
844866 let no_ambiguity = self . r . ambiguity_errors . len ( ) == prev_ambiguity_errors_len;
845867 directive. vis . set ( orig_vis) ;
846868 if let PathResult :: Failed { .. } | PathResult :: NonModule ( ..) = path_res {
@@ -903,7 +925,6 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
903925 }
904926 }
905927 } ;
906-
907928 return Some ( err) ;
908929 }
909930 return None ;
0 commit comments