@@ -843,14 +843,16 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
843
843
self . current_module = directive. parent_scope . module ;
844
844
845
845
let orig_vis = directive. vis . replace ( ty:: Visibility :: Invisible ) ;
846
+ let prev_ambiguity_errors_len = self . ambiguity_errors . len ( ) ;
846
847
let path_res = self . resolve_path ( & directive. module_path , None , & directive. parent_scope ,
847
848
true , directive. span , directive. crate_lint ( ) ) ;
849
+ let no_ambiguity = self . ambiguity_errors . len ( ) == prev_ambiguity_errors_len;
848
850
directive. vis . set ( orig_vis) ;
849
851
let module = match path_res {
850
852
PathResult :: Module ( module) => {
851
853
// Consistency checks, analogous to `finalize_current_module_macro_resolutions`.
852
854
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 {
854
856
span_bug ! ( directive. span, "inconsistent resolution for an import" ) ;
855
857
}
856
858
} else {
@@ -864,30 +866,32 @@ impl<'a, 'b:'a, 'c: 'b> ImportResolver<'a, 'b, 'c> {
864
866
module
865
867
}
866
868
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
+ }
870
873
return None ;
871
874
}
872
875
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 ;
886
889
}
887
890
PathResult :: NonModule ( path_res) if path_res. base_def ( ) == Def :: Err => {
891
+ if no_ambiguity {
892
+ assert ! ( directive. imported_module. get( ) . is_none( ) ) ;
893
+ }
888
894
// The error was already reported earlier.
889
- assert ! ( !self . ambiguity_errors. is_empty( ) ||
890
- directive. imported_module. get( ) . is_none( ) ) ;
891
895
return None ;
892
896
}
893
897
PathResult :: Indeterminate | PathResult :: NonModule ( ..) => unreachable ! ( ) ,
0 commit comments