@@ -203,11 +203,15 @@ fn report_elision_failure(
203
203
{
204
204
let mut m = String :: new ( ) ;
205
205
let len = params. len ( ) ;
206
+ let mut any_lifetimes = false ;
207
+
206
208
for ( i, info) in params. into_iter ( ) . enumerate ( ) {
207
209
let ElisionFailureInfo {
208
210
name, lifetime_count : n, have_bound_regions
209
211
} = info;
210
212
213
+ any_lifetimes = any_lifetimes || ( n > 0 ) ;
214
+
211
215
let help_name = if name. is_empty ( ) {
212
216
format ! ( "argument {}" , i + 1 )
213
217
} else {
@@ -229,17 +233,26 @@ fn report_elision_failure(
229
233
m. push_str ( ", " ) ;
230
234
}
231
235
}
232
- if len == 1 {
233
- fileline_help ! ( tcx. sess, default_span,
234
- "this function's return type contains a borrowed value, but \
235
- the signature does not say which {} it is borrowed from",
236
- m) ;
237
- } else if len == 0 {
236
+
237
+ if len == 0 {
238
238
fileline_help ! ( tcx. sess, default_span,
239
239
"this function's return type contains a borrowed value, but \
240
240
there is no value for it to be borrowed from") ;
241
241
fileline_help ! ( tcx. sess, default_span,
242
242
"consider giving it a 'static lifetime" ) ;
243
+ } else if !any_lifetimes {
244
+ fileline_help ! ( tcx. sess, default_span,
245
+ "this function's return type contains a borrowed value with \
246
+ an elided lifetime, but the lifetime cannot be derived from \
247
+ the arguments") ;
248
+ fileline_help ! ( tcx. sess, default_span,
249
+ "consider giving it an explicit bounded or 'static \
250
+ lifetime") ;
251
+ } else if len == 1 {
252
+ fileline_help ! ( tcx. sess, default_span,
253
+ "this function's return type contains a borrowed value, but \
254
+ the signature does not say which {} it is borrowed from",
255
+ m) ;
243
256
} else {
244
257
fileline_help ! ( tcx. sess, default_span,
245
258
"this function's return type contains a borrowed value, but \
0 commit comments