@@ -24,7 +24,7 @@ use rustc_hir::def_id::{CRATE_DEF_ID, DefId};
2424use rustc_hir:: { MissingLifetimeKind , PrimTy } ;
2525use rustc_middle:: ty;
2626use 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} ;
2828use rustc_span:: edition:: Edition ;
2929use rustc_span:: hygiene:: MacroKind ;
3030use rustc_span:: { DUMMY_SP , Ident , Span , Symbol , kw, sym} ;
@@ -2919,23 +2919,35 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
29192919 )
29202920 . with_span_label ( lifetime_ref. ident . span , "undeclared lifetime" )
29212921 } ;
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+
29392951 err. emit ( ) ;
29402952 }
29412953
0 commit comments