@@ -339,8 +339,6 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
339
339
340
340
// Try Levenshtein algorithm.
341
341
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
-
344
342
// Try context-dependent help if relaxed lookup didn't work.
345
343
if let Some ( res) = res {
346
344
if self . smart_resolve_context_dependent_help (
@@ -351,14 +349,18 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
351
349
& path_str,
352
350
& fallback_label,
353
351
) {
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) ;
354
354
return ( err, candidates) ;
355
355
}
356
356
}
357
357
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.
360
362
err. span_label ( base_span, fallback_label) ;
361
- self . type_ascription_suggestion ( & mut err , base_span ) ;
363
+
362
364
match self . diagnostic_metadata . current_let_binding {
363
365
Some ( ( pat_sp, Some ( ty_sp) , None ) ) if ty_sp. contains ( base_span) && could_be_expr => {
364
366
err. span_suggestion_short (
@@ -869,7 +871,7 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
869
871
start. to ( sm. next_point ( start) )
870
872
}
871
873
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 {
873
875
let sm = self . r . session . source_map ( ) ;
874
876
let base_snippet = sm. span_to_snippet ( base_span) ;
875
877
if let Some ( & sp) = self . diagnostic_metadata . current_type_ascription . last ( ) {
@@ -939,9 +941,11 @@ impl<'a> LateResolutionVisitor<'a, '_, '_> {
939
941
"expecting a type here because of type ascription" ,
940
942
) ;
941
943
}
944
+ return show_label;
942
945
}
943
946
}
944
947
}
948
+ false
945
949
}
946
950
947
951
fn find_module ( & mut self , def_id : DefId ) -> Option < ( Module < ' a > , ImportSuggestion ) > {
0 commit comments