@@ -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} ;
@@ -2874,23 +2874,35 @@ impl<'ast, 'ra: 'ast, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> {
28742874 )
28752875 . with_span_label ( lifetime_ref. ident . span , "undeclared lifetime" )
28762876 } ;
2877- self . suggest_introducing_lifetime (
2878- & mut err,
2879- Some ( lifetime_ref. ident . name . as_str ( ) ) ,
2880- |err, _, span, message, suggestion, span_suggs| {
2881- err. multipart_suggestion_with_style (
2882- message,
2883- std:: iter:: once ( ( span, suggestion) ) . chain ( span_suggs. clone ( ) ) . collect ( ) ,
2884- Applicability :: MaybeIncorrect ,
2885- if span_suggs. is_empty ( ) {
2886- SuggestionStyle :: ShowCode
2887- } else {
2888- SuggestionStyle :: ShowAlways
2889- } ,
2890- ) ;
2891- true
2892- } ,
2893- ) ;
2877+
2878+ // Check if this is a typo of `'static`.
2879+ if edit_distance ( lifetime_ref. ident . name . as_str ( ) , "'static" , 2 ) . is_some ( ) {
2880+ err. span_suggestion_verbose (
2881+ lifetime_ref. ident . span ,
2882+ "you may have misspelled the `'static` lifetime" ,
2883+ "'static" ,
2884+ Applicability :: MachineApplicable ,
2885+ ) ;
2886+ } else {
2887+ self . suggest_introducing_lifetime (
2888+ & mut err,
2889+ Some ( lifetime_ref. ident . name . as_str ( ) ) ,
2890+ |err, _, span, message, suggestion, span_suggs| {
2891+ err. multipart_suggestion_with_style (
2892+ message,
2893+ std:: iter:: once ( ( span, suggestion) ) . chain ( span_suggs. clone ( ) ) . collect ( ) ,
2894+ Applicability :: MaybeIncorrect ,
2895+ if span_suggs. is_empty ( ) {
2896+ SuggestionStyle :: ShowCode
2897+ } else {
2898+ SuggestionStyle :: ShowAlways
2899+ } ,
2900+ ) ;
2901+ true
2902+ } ,
2903+ ) ;
2904+ }
2905+
28942906 err. emit ( ) ;
28952907 }
28962908
0 commit comments