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