rust/src/test/ui/nll/borrowed-universal-error-2.stderr
David Wood b342f00179
Only annotate if borrow is returned.
Error now correctly checks whether the borrow that does not live
long enough is being returned before annotating the error with the
arguments and return type from the signature - as this would not be
relevant if the borrow was not being returned.
2018-09-23 14:18:35 +02:00

22 lines
981 B
Plaintext

error[E0597]: `v` does not live long enough
--> $DIR/borrowed-universal-error-2.rs:16:5
|
LL | fn foo<'a>(x: &'a (u32,)) -> &'a u32 {
| -- -- also has lifetime `'a`
| |
| has lifetime `'a`
LL | let v = 22;
LL | &v
| ^^ `v` would have to be valid for `'a`...
LL | //~^ ERROR `v` does not live long enough [E0597]
LL | }
| - ...but `v` will be dropped here, when the function `foo` returns
|
= help: use data from the highlighted arguments which match the `'a` lifetime of the return type
= note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
= note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
error: aborting due to previous error
For more information about this error, try `rustc --explain E0597`.