@@ -2914,71 +2914,50 @@ fn add_missing_lifetime_specifiers_label(
29142914 if count > 1 {
29152915 err. span_label ( span, format ! ( "expected {} lifetime parameters" , count) ) ;
29162916 } else {
2917- let mut introduce_suggestion = vec ! [ ] ;
2918- if let Some ( generics) = missing_named_lifetime_spots. iter ( ) . last ( ) {
2919- introduce_suggestion. push ( match & generics. params {
2920- [ ] => ( generics. span , "<'lifetime>" . to_string ( ) ) ,
2921- [ param, ..] => ( param. span . shrink_to_lo ( ) , "'lifetime, " . to_string ( ) ) ,
2922- } ) ;
2923- }
2917+ let suggest_existing = |err : & mut DiagnosticBuilder < ' _ > , sugg| {
2918+ err. span_suggestion (
2919+ span,
2920+ "consider using the named lifetime" ,
2921+ sugg,
2922+ Applicability :: MaybeIncorrect ,
2923+ ) ;
2924+ } ;
2925+ let suggest_new = |err : & mut DiagnosticBuilder < ' _ > , sugg| {
2926+ err. span_label ( span, "expected named lifetime parameter" ) ;
2927+
2928+ if let Some ( generics) = missing_named_lifetime_spots. iter ( ) . last ( ) {
2929+ let mut introduce_suggestion = vec ! [ ] ;
2930+ introduce_suggestion. push ( match & generics. params {
2931+ [ ] => ( generics. span , "<'lifetime>" . to_string ( ) ) ,
2932+ [ param, ..] => ( param. span . shrink_to_lo ( ) , "'lifetime, " . to_string ( ) ) ,
2933+ } ) ;
2934+ introduce_suggestion. push ( ( span, sugg) ) ;
2935+ err. multipart_suggestion (
2936+ "consider introducing a named lifetime parameter" ,
2937+ introduce_suggestion,
2938+ Applicability :: MaybeIncorrect ,
2939+ ) ;
2940+ }
2941+ } ;
29242942
29252943 match ( lifetime_names. len ( ) , lifetime_names. iter ( ) . next ( ) , snippet) {
29262944 ( 1 , Some ( name) , Some ( "&" ) ) => {
2927- err. span_suggestion (
2928- span,
2929- "consider using the named lifetime" ,
2930- format ! ( "&{} " , name) ,
2931- Applicability :: MaybeIncorrect ,
2932- ) ;
2945+ suggest_existing ( err, format ! ( "&{} " , name) ) ;
29332946 }
29342947 ( 1 , Some ( name) , Some ( "'_" ) ) => {
2935- err. span_suggestion (
2936- span,
2937- "consider using the named lifetime" ,
2938- name. to_string ( ) ,
2939- Applicability :: MaybeIncorrect ,
2940- ) ;
2948+ suggest_existing ( err, name. to_string ( ) ) ;
29412949 }
29422950 ( 1 , Some ( name) , Some ( snippet) ) if !snippet. ends_with ( ">" ) => {
2943- err. span_suggestion (
2944- span,
2945- "consider using the named lifetime" ,
2946- format ! ( "{}<{}>" , snippet, name) ,
2947- Applicability :: MaybeIncorrect ,
2948- ) ;
2951+ suggest_existing ( err, format ! ( "{}<{}>" , snippet, name) ) ;
29492952 }
29502953 ( 0 , _, Some ( "&" ) ) => {
2951- err. span_label ( span, "expected named lifetime parameter" ) ;
2952- if !introduce_suggestion. is_empty ( ) {
2953- introduce_suggestion. push ( ( span, "&'lifetime " . to_string ( ) ) ) ;
2954- err. multipart_suggestion (
2955- "consider introducing a named lifetime parameter" ,
2956- introduce_suggestion,
2957- Applicability :: MaybeIncorrect ,
2958- ) ;
2959- }
2954+ suggest_new ( err, "&'lifetime " . to_string ( ) ) ;
29602955 }
29612956 ( 0 , _, Some ( "'_" ) ) => {
2962- err. span_label ( span, "expected named lifetime parameter" ) ;
2963- if !introduce_suggestion. is_empty ( ) {
2964- introduce_suggestion. push ( ( span, "'lifetime" . to_string ( ) ) ) ;
2965- err. multipart_suggestion (
2966- "consider introducing a named lifetime parameter" ,
2967- introduce_suggestion,
2968- Applicability :: MaybeIncorrect ,
2969- ) ;
2970- }
2957+ suggest_new ( err, "'lifetime" . to_string ( ) ) ;
29712958 }
29722959 ( 0 , _, Some ( snippet) ) if !snippet. ends_with ( ">" ) => {
2973- err. span_label ( span, "expected named lifetime parameter" ) ;
2974- if !introduce_suggestion. is_empty ( ) {
2975- introduce_suggestion. push ( ( span, format ! ( "{}<'lifetime>" , snippet) ) ) ;
2976- err. multipart_suggestion (
2977- "consider introducing a named lifetime parameter" ,
2978- introduce_suggestion,
2979- Applicability :: MaybeIncorrect ,
2980- ) ;
2981- }
2960+ suggest_new ( err, format ! ( "{}<'lifetime>" , snippet) ) ;
29822961 }
29832962 _ => {
29842963 err. span_label ( span, "expected lifetime parameter" ) ;
0 commit comments