@@ -339,8 +339,6 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
339339
340340 // Try Levenshtein algorithm.
341341 let typo_sugg = self . lookup_typo_candidate ( path, ns, is_expected, span) ;
342- let levenshtein_worked = self . r . add_typo_suggestion ( & mut err, typo_sugg, ident_span) ;
343-
344342 // Try context-dependent help if relaxed lookup didn't work.
345343 if let Some ( res) = res {
346344 if self . smart_resolve_context_dependent_help (
@@ -351,14 +349,18 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
351349 & path_str,
352350 & fallback_label,
353351 ) {
352+ // We do this to avoid losing a secondary span when we override the main error span.
353+ self . r . add_typo_suggestion ( & mut err, typo_sugg, ident_span) ;
354354 return ( err, candidates) ;
355355 }
356356 }
357357
358- // Fallback label.
359- if !levenshtein_worked {
358+ if !self . type_ascription_suggestion ( & mut err, base_span)
359+ && !self . r . add_typo_suggestion ( & mut err, typo_sugg, ident_span)
360+ {
361+ // Fallback label.
360362 err. span_label ( base_span, fallback_label) ;
361- self . type_ascription_suggestion ( & mut err , base_span ) ;
363+
362364 match self . diagnostic_metadata . current_let_binding {
363365 Some ( ( pat_sp, Some ( ty_sp) , None ) ) if ty_sp. contains ( base_span) && could_be_expr => {
364366 err. span_suggestion_short (
@@ -869,7 +871,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
869871 start. to ( sm. next_point ( start) )
870872 }
871873
872- fn type_ascription_suggestion ( & self , err : & mut DiagnosticBuilder < ' _ > , base_span : Span ) {
874+ fn type_ascription_suggestion ( & self , err : & mut DiagnosticBuilder < ' _ > , base_span : Span ) -> bool {
873875 let sm = self . r . session . source_map ( ) ;
874876 let base_snippet = sm. span_to_snippet ( base_span) ;
875877 if let Some ( & sp) = self . diagnostic_metadata . current_type_ascription . last ( ) {
@@ -939,9 +941,11 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
939941 "expecting a type here because of type ascription" ,
940942 ) ;
941943 }
944+ return show_label;
942945 }
943946 }
944947 }
948+ false
945949 }
946950
947951 fn find_module ( & mut self , def_id : DefId ) -> Option < ( Module < ' a > , ImportSuggestion ) > {
0 commit comments