mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
Fix incorrect lifetime suggestion
This commit is contained in:
parent
d30252e359
commit
dec7f00e15
@ -2853,8 +2853,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||
"this function's return type contains a borrowed value, but there is no value \
|
||||
for it to be borrowed from",
|
||||
);
|
||||
maybe_static = true;
|
||||
if in_scope_lifetimes.is_empty() {
|
||||
maybe_static = true;
|
||||
in_scope_lifetimes = vec![(
|
||||
Ident::with_dummy_span(kw::StaticLifetime),
|
||||
(DUMMY_NODE_ID, LifetimeRes::Static),
|
||||
@ -2865,8 +2865,8 @@ impl<'a: 'ast, 'ast, 'tcx> LateResolutionVisitor<'a, '_, 'ast, 'tcx> {
|
||||
"this function's return type contains a borrowed value with an elided \
|
||||
lifetime, but the lifetime cannot be derived from the arguments",
|
||||
);
|
||||
maybe_static = true;
|
||||
if in_scope_lifetimes.is_empty() {
|
||||
maybe_static = true;
|
||||
in_scope_lifetimes = vec![(
|
||||
Ident::with_dummy_span(kw::StaticLifetime),
|
||||
(DUMMY_NODE_ID, LifetimeRes::Static),
|
||||
|
@ -88,19 +88,10 @@ LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
|
||||
| ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
|
||||
help: consider using the `'a` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &'a isize {
|
||||
| ++
|
||||
help: instead, you are more likely to want to change the argument to be borrowed...
|
||||
|
|
||||
LL | fn k<'a, T: WithLifetime<'a>>(_x: &T::Output) -> &isize {
|
||||
| +
|
||||
help: ...or alternatively, you might want to return an owned value
|
||||
|
|
||||
LL - fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> &isize {
|
||||
LL + fn k<'a, T: WithLifetime<'a>>(_x: T::Output) -> isize {
|
||||
|
|
||||
|
||||
error[E0106]: missing lifetime specifier
|
||||
--> $DIR/lifetime-elision-return-type-requires-explicit-lifetime.rs:45:37
|
||||
@ -109,18 +100,10 @@ LL | fn l<'a>(_: &'a str, _: &'a str) -> &str { "" }
|
||||
| ------- ------- ^ expected named lifetime parameter
|
||||
|
|
||||
= help: this function's return type contains a borrowed value with an elided lifetime, but the lifetime cannot be derived from the arguments
|
||||
help: consider using the `'a` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
|
||||
help: consider using the `'a` lifetime
|
||||
|
|
||||
LL | fn l<'a>(_: &'a str, _: &'a str) -> &'a str { "" }
|
||||
| ++
|
||||
help: instead, you are more likely to want to change one of the arguments to be borrowed...
|
||||
|
|
||||
LL | fn l<'a>(_: &&'a str, _: &&'a str) -> &str { "" }
|
||||
| + +
|
||||
help: ...or alternatively, you might want to return an owned value
|
||||
|
|
||||
LL | fn l<'a>(_: &'a str, _: &'a str) -> String { "" }
|
||||
| ~~~~~~
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user