Suggest return lifetime when there's only one named lifetime

This commit is contained in:
Esteban Küber 2019-03-12 14:57:13 -07:00
parent 7486b9c208
commit 795d307f10
3 changed files with 60 additions and 4 deletions

View file

@ -0,0 +1,8 @@
struct Thing<'a>(&'a ());
fn func1<'a>(_arg: &'a Thing) -> &() { unimplemented!() }
//~^ ERROR missing lifetime specifier
fn func2<'a>(_arg: &Thing<'a>) -> &() { unimplemented!() }
//~^ ERROR missing lifetime specifier
fn main() {}

View file

@ -0,0 +1,19 @@
error[E0106]: missing lifetime specifier
--> $DIR/return-without-lifetime.rs:3:34
|
LL | fn func1<'a>(_arg: &'a Thing) -> &() { unimplemented!() }
| ^ help: consider using the named lifetime `'a`: `&'a`
|
= help: this function's return type contains a borrowed value, but the signature does not say which one of `_arg`'s 2 lifetimes it is borrowed from
error[E0106]: missing lifetime specifier
--> $DIR/return-without-lifetime.rs:5:35
|
LL | fn func2<'a>(_arg: &Thing<'a>) -> &() { unimplemented!() }
| ^ help: consider using the named lifetime `'a`: `&'a`
|
= help: this function's return type contains a borrowed value, but the signature does not say which one of `_arg`'s 2 lifetimes it is borrowed from
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0106`.