Auto merge of #30102 - jFransham:feature/better-lifetime-errors, r=Manishearth
Fixes #30086
This commit is contained in:
commit
d75f861518
@ -203,11 +203,15 @@ fn report_elision_failure(
|
|||||||
{
|
{
|
||||||
let mut m = String::new();
|
let mut m = String::new();
|
||||||
let len = params.len();
|
let len = params.len();
|
||||||
|
let mut any_lifetimes = false;
|
||||||
|
|
||||||
for (i, info) in params.into_iter().enumerate() {
|
for (i, info) in params.into_iter().enumerate() {
|
||||||
let ElisionFailureInfo {
|
let ElisionFailureInfo {
|
||||||
name, lifetime_count: n, have_bound_regions
|
name, lifetime_count: n, have_bound_regions
|
||||||
} = info;
|
} = info;
|
||||||
|
|
||||||
|
any_lifetimes = any_lifetimes || (n > 0);
|
||||||
|
|
||||||
let help_name = if name.is_empty() {
|
let help_name = if name.is_empty() {
|
||||||
format!("argument {}", i + 1)
|
format!("argument {}", i + 1)
|
||||||
} else {
|
} else {
|
||||||
@ -229,17 +233,26 @@ fn report_elision_failure(
|
|||||||
m.push_str(", ");
|
m.push_str(", ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len == 1 {
|
|
||||||
fileline_help!(tcx.sess, default_span,
|
if len == 0 {
|
||||||
"this function's return type contains a borrowed value, but \
|
|
||||||
the signature does not say which {} it is borrowed from",
|
|
||||||
m);
|
|
||||||
} else if len == 0 {
|
|
||||||
fileline_help!(tcx.sess, default_span,
|
fileline_help!(tcx.sess, default_span,
|
||||||
"this function's return type contains a borrowed value, but \
|
"this function's return type contains a borrowed value, but \
|
||||||
there is no value for it to be borrowed from");
|
there is no value for it to be borrowed from");
|
||||||
fileline_help!(tcx.sess, default_span,
|
fileline_help!(tcx.sess, default_span,
|
||||||
"consider giving it a 'static lifetime");
|
"consider giving it a 'static lifetime");
|
||||||
|
} else if !any_lifetimes {
|
||||||
|
fileline_help!(tcx.sess, default_span,
|
||||||
|
"this function's return type contains a borrowed value with \
|
||||||
|
an elided lifetime, but the lifetime cannot be derived from \
|
||||||
|
the arguments");
|
||||||
|
fileline_help!(tcx.sess, default_span,
|
||||||
|
"consider giving it an explicit bounded or 'static \
|
||||||
|
lifetime");
|
||||||
|
} else if len == 1 {
|
||||||
|
fileline_help!(tcx.sess, default_span,
|
||||||
|
"this function's return type contains a borrowed value, but \
|
||||||
|
the signature does not say which {} it is borrowed from",
|
||||||
|
m);
|
||||||
} else {
|
} else {
|
||||||
fileline_help!(tcx.sess, default_span,
|
fileline_help!(tcx.sess, default_span,
|
||||||
"this function's return type contains a borrowed value, but \
|
"this function's return type contains a borrowed value, but \
|
||||||
|
@ -14,6 +14,10 @@ fn parse_type(iter: Box<Iterator<Item=&str>+'static>) -> &str { iter.next() }
|
|||||||
|
|
||||||
fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
|
fn parse_type_2(iter: fn(&u8)->&u8) -> &str { iter() }
|
||||||
//~^ ERROR missing lifetime specifier [E0106]
|
//~^ ERROR missing lifetime specifier [E0106]
|
||||||
//~^^ HELP 0 elided free lifetimes
|
//~^^ HELP lifetime cannot be derived
|
||||||
|
|
||||||
|
fn parse_type_3() -> &str { unimplemented!() }
|
||||||
|
//~^ ERROR missing lifetime specifier [E0106]
|
||||||
|
//~^^ HELP no value for it to be borrowed from
|
||||||
|
|
||||||
fn main() {}
|
fn main() {}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user