Skip to content

Commit a1a48c4

Browse files
author
Jack Fransham
committed
Better errors when rustc cannot derive lifetimes
1 parent 323781c commit a1a48c4

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc_typeck/astconv.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -203,11 +203,15 @@ fn report_elision_failure(
203203
{
204204
let mut m = String::new();
205205
let len = params.len();
206+
let mut any_lifetimes = false;
207+
206208
for (i, info) in params.into_iter().enumerate() {
207209
let ElisionFailureInfo {
208210
name, lifetime_count: n, have_bound_regions
209211
} = info;
210212

213+
any_lifetimes = any_lifetimes || (n > 0);
214+
211215
let help_name = if name.is_empty() {
212216
format!("argument {}", i + 1)
213217
} else {
@@ -229,7 +233,16 @@ fn report_elision_failure(
229233
m.push_str(", ");
230234
}
231235
}
232-
if len == 1 {
236+
237+
if !any_lifetimes {
238+
fileline_help!(tcx.sess, default_span,
239+
"this function's return type contains a borrowed value with \
240+
an elided lifetime, but the lifetime cannot be derived from \
241+
the arguments");
242+
fileline_help!(tcx.sess, default_span,
243+
"consider giving it an explicit bounded or 'static \
244+
lifetime");
245+
} else if len == 1 {
233246
fileline_help!(tcx.sess, default_span,
234247
"this function's return type contains a borrowed value, but \
235248
the signature does not say which {} it is borrowed from",

0 commit comments

Comments
 (0)