]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-30438-c.nll.stderr
e7f2efcb01a54028de8e788df79887bb05c69e7c
[rust.git] / src / test / ui / issues / issue-30438-c.nll.stderr
1 error[E0597]: `x` does not live long enough
2   --> $DIR/issue-30438-c.rs:19:5
3    |
4 LL | fn silly<'y, 'z>(_s: &'y Test<'z>) -> &'y <Test<'z> as Trait>::Out where 'z: 'static {
5    |                      ------------     ---------------------------- has type `&'y <Test<'z> as Trait>::Out`
6    |                      |
7    |                      has type `&'y Test<'z>`
8 LL |     let x = Test { s: "this cannot last" };
9 LL |     &x
10    |     ^^ `x` would have to be valid for `'y`
11 LL |     //~^ ERROR: `x` does not live long enough
12 LL | }
13    | - ...but `x` is only valid for the duration of the `silly` function, so it is dropped here while still borrowed
14    |
15    = note: functions cannot return a borrow to data owned within the function's scope, functions can only return borrows to data passed as arguments
16    = note: to learn more, visit <https://doc.rust-lang.org/book/second-edition/ch04-02-references-and-borrowing.html#dangling-references>
17
18 error: aborting due to previous error
19
20 For more information about this error, try `rustc --explain E0597`.