@@ -1035,6 +1035,8 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1035
1035
lifetime_names : & FxHashSet < ast:: Ident > ,
1036
1036
params : & [ ElisionFailureInfo ] ,
1037
1037
) {
1038
+ let snippet = self . tcx . sess . source_map ( ) . span_to_snippet ( span) . ok ( ) ;
1039
+
1038
1040
err. span_label (
1039
1041
span,
1040
1042
& format ! (
@@ -1044,11 +1046,10 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1044
1046
) ,
1045
1047
) ;
1046
1048
1047
- let snippet = self . tcx . sess . source_map ( ) . span_to_snippet ( span) . ok ( ) ;
1048
1049
let suggest_existing = |err : & mut DiagnosticBuilder < ' _ > , sugg| {
1049
1050
err. span_suggestion_verbose (
1050
1051
span,
1051
- "consider using the named lifetime" ,
1052
+ & format ! ( "consider using the `{}` lifetime" , lifetime_names . iter ( ) . next ( ) . unwrap ( ) ) ,
1052
1053
sugg,
1053
1054
Applicability :: MaybeIncorrect ,
1054
1055
) ;
@@ -1138,6 +1139,20 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
1138
1139
( 0 , _, Some ( snippet) ) if !snippet. ends_with ( '>' ) && count == 1 => {
1139
1140
suggest_new ( err, & format ! ( "{}<'a>" , snippet) ) ;
1140
1141
}
1142
+ ( n, ..) if n > 1 => {
1143
+ let spans: Vec < Span > = lifetime_names. iter ( ) . map ( |lt| lt. span ) . collect ( ) ;
1144
+ err. span_note ( spans, "these named lifetimes are available to use" ) ;
1145
+ if Some ( "" ) == snippet. as_deref ( ) {
1146
+ // This happens when we have `Foo<T>` where we point at the space before `T`,
1147
+ // but this can be confusing so we give a suggestion with placeholders.
1148
+ err. span_suggestion_verbose (
1149
+ span,
1150
+ "consider using one of the available lifetimes here" ,
1151
+ "'lifetime, " . repeat ( count) ,
1152
+ Applicability :: HasPlaceholders ,
1153
+ ) ;
1154
+ }
1155
+ }
1141
1156
_ => { }
1142
1157
}
1143
1158
}
0 commit comments