@@ -968,18 +968,14 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
968
968
for missing in & self . missing_named_lifetime_spots {
969
969
match missing {
970
970
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 {
975
973
hir:: GenericParamKind :: Type {
976
974
synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
977
975
..
978
976
} => false ,
979
977
_ => true ,
980
- } )
981
- . next ( )
982
- {
978
+ } ) {
983
979
( param. span . shrink_to_lo ( ) , format ! ( "{}, " , lifetime_ref) )
984
980
} else {
985
981
( generics. span , format ! ( "<{}>" , lifetime_ref) )
@@ -1053,25 +1049,24 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1053
1049
Applicability :: MaybeIncorrect ,
1054
1050
) ;
1055
1051
} ;
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" ) ;
1059
1054
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 {
1065
1060
MissingLifetimeSpot :: Generics ( generics) => {
1066
1061
msg = "consider introducing a named lifetime parameter" . to_string ( ) ;
1067
1062
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 {
1069
1064
hir:: GenericParamKind :: Type {
1070
1065
synthetic : Some ( hir:: SyntheticTyParamKind :: ImplTrait ) ,
1071
1066
..
1072
1067
} => false ,
1073
1068
_ => true ,
1074
- } ) . next ( ) {
1069
+ } ) {
1075
1070
( param. span . shrink_to_lo ( ) , "'a, " . to_string ( ) )
1076
1071
} else {
1077
1072
( generics. span , "<'a>" . to_string ( ) )
@@ -1090,30 +1085,29 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1090
1085
( * span, span_type. suggestion ( "'a" ) )
1091
1086
}
1092
1087
} ) ;
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 ..] ) ) ) ;
1104
1097
}
1105
1098
}
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
- }
1115
1099
}
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
+ } ;
1117
1111
1118
1112
match (
1119
1113
lifetime_names. len ( ) ,
0 commit comments