@@ -843,14 +843,16 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
843843 self . current_module = directive. parent_scope . module ;
844844
845845 let orig_vis = directive. vis . replace ( ty:: Visibility :: Invisible ) ;
846+ let prev_ambiguity_errors_len = self . ambiguity_errors . len ( ) ;
846847 let path_res = self . resolve_path ( & directive. module_path , None , & directive. parent_scope ,
847848 true , directive. span , directive. crate_lint ( ) ) ;
849+ let no_ambiguity = self . ambiguity_errors . len ( ) == prev_ambiguity_errors_len;
848850 directive. vis . set ( orig_vis) ;
849851 let module = match path_res {
850852 PathResult :: Module ( module) => {
851853 // Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
852854 if let Some ( initial_module) = directive. imported_module . get ( ) {
853- if module != initial_module && self . ambiguity_errors . is_empty ( ) {
855+ if module != initial_module && no_ambiguity {
854856 span_bug ! ( directive. span, "inconsistent resolution for an import" ) ;
855857 }
856858 } else {
@@ -864,30 +866,32 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
864866 module
865867 }
866868 PathResult :: Failed ( span, msg, false ) => {
867- assert ! ( !self . ambiguity_errors. is_empty( ) ||
868- directive. imported_module. get( ) . is_none( ) ) ;
869- resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
869+ if no_ambiguity {
870+ assert ! ( directive. imported_module. get( ) . is_none( ) ) ;
871+ resolve_error ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
872+ }
870873 return None ;
871874 }
872875 PathResult :: Failed ( span, msg, true ) => {
873- assert ! ( ! self . ambiguity_errors . is_empty ( ) ||
874- directive. imported_module. get( ) . is_none( ) ) ;
875- return if let Some ( ( suggested_path , note ) ) = self . make_path_suggestion (
876- span , directive . module_path . clone ( ) , & directive. parent_scope
877- ) {
878- Some ( (
879- span ,
880- format ! ( "did you mean `{}`?" , Segment :: names_to_string ( & suggested_path ) ) ,
881- note ,
882- ) )
883- } else {
884- Some ( ( span , msg , None ) )
885- } ;
876+ if no_ambiguity {
877+ assert ! ( directive. imported_module. get( ) . is_none( ) ) ;
878+ return Some ( match self . make_path_suggestion ( span , directive . module_path . clone ( ) ,
879+ & directive. parent_scope ) {
880+ Some ( ( suggestion , note ) ) => (
881+ span ,
882+ format ! ( "did you mean `{}`?" , Segment :: names_to_string ( & suggestion ) ) ,
883+ note ,
884+ ) ,
885+ None => ( span , msg , None ) ,
886+ } ) ;
887+ }
888+ return None ;
886889 }
887890 PathResult :: NonModule ( path_res) if path_res. base_def ( ) == Def :: Err => {
891+ if no_ambiguity {
892+ assert ! ( directive. imported_module. get( ) . is_none( ) ) ;
893+ }
888894 // The error was already reported earlier.
889- assert ! ( !self . ambiguity_errors. is_empty( ) ||
890- directive. imported_module. get( ) . is_none( ) ) ;
891895 return None ;
892896 }
893897 PathResult :: Indeterminate | PathResult :: NonModule ( ..) => unreachable ! ( ) ,
0 commit comments