@@ -968,18 +968,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
968968 for missing in & self . missing_named_lifetime_spots {
969969 match missing {
970970 MissingLifetimeSpot :: Generics ( generics) => {
971- let ( span, sugg) = if let Some ( param) = generics
972- . params
973- . iter ( )
974- . filter ( |p| match p. kind {
971+ let ( span, sugg) = if let Some ( param) =
972+ generics. params . iter ( ) . find ( |p| match p. kind {
975973 hir:: GenericParamKind :: Type {
976974 synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
977975 ..
978976 } => false ,
979977 _ => true ,
980- } )
981- . next ( )
982- {
978+ } ) {
983979 ( param. span . shrink_to_lo ( ) , format ! ( "{}, " , lifetime_ref) )
984980 } else {
985981 ( generics. span , format ! ( "<{}>" , lifetime_ref) )
@@ -1053,25 +1049,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10531049 Applicability :: MaybeIncorrect ,
10541050 ) ;
10551051 } ;
1056- let suggest_new =
1057- |err : & mut DiagnosticBuilder < ' _ > , sugg : & str | {
1058- err. span_label ( span, "expected named lifetime parameter" ) ;
1052+ let suggest_new = |err : & mut DiagnosticBuilder < ' _ > , sugg : & str | {
1053+ err. span_label ( span, "expected named lifetime parameter" ) ;
10591054
1060- for missing in self . missing_named_lifetime_spots . iter ( ) . rev ( ) {
1061- let mut introduce_suggestion = vec ! [ ] ;
1062- let msg;
1063- let should_break;
1064- introduce_suggestion. push ( match missing {
1055+ for missing in self . missing_named_lifetime_spots . iter ( ) . rev ( ) {
1056+ let mut introduce_suggestion = vec ! [ ] ;
1057+ let msg;
1058+ let should_break;
1059+ introduce_suggestion. push ( match missing {
10651060 MissingLifetimeSpot :: Generics ( generics) => {
10661061 msg = "consider introducing a named lifetime parameter" . to_string ( ) ;
10671062 should_break = true ;
1068- if let Some ( param) = generics. params . iter ( ) . filter ( |p| match p. kind {
1063+ if let Some ( param) = generics. params . iter ( ) . find ( |p| match p. kind {
10691064 hir:: GenericParamKind :: Type {
10701065 synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
10711066 ..
10721067 } => false ,
10731068 _ => true ,
1074- } ) . next ( ) {
1069+ } ) {
10751070 ( param. span . shrink_to_lo ( ) , "'a, " . to_string ( ) )
10761071 } else {
10771072 ( generics. span , "<'a>" . to_string ( ) )
@@ -1090,30 +1085,29 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
10901085 ( * span, span_type. suggestion ( "'a" ) )
10911086 }
10921087 } ) ;
1093- for param in params {
1094- if let Ok ( snippet) =
1095- self . tcx . sess . source_map ( ) . span_to_snippet ( param. span )
1096- {
1097- if snippet. starts_with ( "&" ) && !snippet. starts_with ( "&'" ) {
1098- introduce_suggestion
1099- . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 1 ..] ) ) ) ;
1100- } else if snippet. starts_with ( "&'_ " ) {
1101- introduce_suggestion
1102- . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 4 ..] ) ) ) ;
1103- }
1088+ for param in params {
1089+ if let Ok ( snippet) = self . tcx . sess . source_map ( ) . span_to_snippet ( param. span )
1090+ {
1091+ if snippet. starts_with ( "&" ) && !snippet. starts_with ( "&'" ) {
1092+ introduce_suggestion
1093+ . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 1 ..] ) ) ) ;
1094+ } else if snippet. starts_with ( "&'_ " ) {
1095+ introduce_suggestion
1096+ . push ( ( param. span , format ! ( "&'a {}" , & snippet[ 4 ..] ) ) ) ;
11041097 }
11051098 }
1106- introduce_suggestion. push ( ( span, sugg. to_string ( ) ) ) ;
1107- err. multipart_suggestion (
1108- & msg,
1109- introduce_suggestion,
1110- Applicability :: MaybeIncorrect ,
1111- ) ;
1112- if should_break {
1113- break ;
1114- }
11151099 }
1116- } ;
1100+ introduce_suggestion. push ( ( span, sugg. to_string ( ) ) ) ;
1101+ err. multipart_suggestion (
1102+ & msg,
1103+ introduce_suggestion,
1104+ Applicability :: MaybeIncorrect ,
1105+ ) ;
1106+ if should_break {
1107+ break ;
1108+ }
1109+ }
1110+ } ;
11171111
11181112 match (
11191113 lifetime_names. len ( ) ,
0 commit comments