@@ -24,7 +24,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
24
24
use rustc_hir:: { MissingLifetimeKind , PrimTy } ;
25
25
use rustc_middle:: ty;
26
26
use rustc_session:: { Session , lint} ;
27
- use rustc_span:: edit_distance:: find_best_match_for_name;
27
+ use rustc_span:: edit_distance:: { edit_distance , find_best_match_for_name} ;
28
28
use rustc_span:: edition:: Edition ;
29
29
use rustc_span:: hygiene:: MacroKind ;
30
30
use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , kw, sym} ;
@@ -2919,23 +2919,35 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
2919
2919
)
2920
2920
. with_span_label ( lifetime_ref. ident . span , "undeclared lifetime" )
2921
2921
} ;
2922
- self . suggest_introducing_lifetime (
2923
- & mut err,
2924
- Some ( lifetime_ref. ident . name . as_str ( ) ) ,
2925
- |err, _, span, message, suggestion, span_suggs| {
2926
- err. multipart_suggestion_with_style (
2927
- message,
2928
- std:: iter:: once ( ( span, suggestion) ) . chain ( span_suggs. clone ( ) ) . collect ( ) ,
2929
- Applicability :: MaybeIncorrect ,
2930
- if span_suggs. is_empty ( ) {
2931
- SuggestionStyle :: ShowCode
2932
- } else {
2933
- SuggestionStyle :: ShowAlways
2934
- } ,
2935
- ) ;
2936
- true
2937
- } ,
2938
- ) ;
2922
+
2923
+ // Check if this is a typo of `'static`.
2924
+ if edit_distance ( lifetime_ref. ident . name . as_str ( ) , "'static" , 2 ) . is_some ( ) {
2925
+ err. span_suggestion_verbose (
2926
+ lifetime_ref. ident . span ,
2927
+ "you may have misspelled the `'static` lifetime" ,
2928
+ "'static" ,
2929
+ Applicability :: MachineApplicable ,
2930
+ ) ;
2931
+ } else {
2932
+ self . suggest_introducing_lifetime (
2933
+ & mut err,
2934
+ Some ( lifetime_ref. ident . name . as_str ( ) ) ,
2935
+ |err, _, span, message, suggestion, span_suggs| {
2936
+ err. multipart_suggestion_with_style (
2937
+ message,
2938
+ std:: iter:: once ( ( span, suggestion) ) . chain ( span_suggs. clone ( ) ) . collect ( ) ,
2939
+ Applicability :: MaybeIncorrect ,
2940
+ if span_suggs. is_empty ( ) {
2941
+ SuggestionStyle :: ShowCode
2942
+ } else {
2943
+ SuggestionStyle :: ShowAlways
2944
+ } ,
2945
+ ) ;
2946
+ true
2947
+ } ,
2948
+ ) ;
2949
+ }
2950
+
2939
2951
err. emit ( ) ;
2940
2952
}
2941
2953
0 commit comments