|
| 1 | +error[E0506]: cannot assign to `*x` because it is borrowed |
| 2 | + --> $DIR/lifetime-name-annotation-2021-ice-123420.rs:12:9 |
| 3 | + | |
| 4 | +LL | let y = &*x; |
| 5 | + | --- `*x` is borrowed here |
| 6 | +LL | *x += 1; |
| 7 | + | ^^^^^^^ `*x` is assigned to here but it was already borrowed |
| 8 | +LL | |
| 9 | +LL | y |
| 10 | + | - returning this value requires that `*x` is borrowed for `'1` |
| 11 | +LL | })() |
| 12 | + | - return type of async closure is &'1 i32 |
| 13 | + |
| 14 | +error: lifetime may not live long enough |
| 15 | + --> $DIR/lifetime-name-annotation-2021-ice-123420.rs:8:28 |
| 16 | + | |
| 17 | +LL | (async move || -> &i32 { |
| 18 | + | ______---------------------_^ |
| 19 | + | | | | |
| 20 | + | | | return type of async closure `{async closure body@$DIR/lifetime-name-annotation-2021-ice-123420.rs:8:28: 15:6}` contains a lifetime `'2` |
| 21 | + | | lifetime `'1` represents this closure's body |
| 22 | +LL | | |
| 23 | +LL | | |
| 24 | +LL | | let y = &*x; |
| 25 | +... | |
| 26 | +LL | | y |
| 27 | +LL | | })() |
| 28 | + | |_____^ returning this value requires that `'1` must outlive `'2` |
| 29 | + | |
| 30 | + = note: closure implements `FnMut`, so references to captured variables can't escape the closure |
| 31 | + |
| 32 | +error[E0700]: hidden type for `impl Future` captures lifetime that does not appear in bounds |
| 33 | + --> $DIR/lifetime-name-annotation-2021-ice-123420.rs:8:5 |
| 34 | + | |
| 35 | +LL | pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future { |
| 36 | + | -------- ----------- opaque type defined here |
| 37 | + | | |
| 38 | + | hidden type `{async closure body@$DIR/lifetime-name-annotation-2021-ice-123420.rs:8:28: 15:6}` captures the anonymous lifetime defined here |
| 39 | +LL | / (async move || -> &i32 { |
| 40 | +LL | | |
| 41 | +LL | | |
| 42 | +LL | | let y = &*x; |
| 43 | +... | |
| 44 | +LL | | y |
| 45 | +LL | | })() |
| 46 | + | |________^ |
| 47 | + | |
| 48 | +help: to declare that `impl Future` captures `'_`, you can add an explicit `'_` lifetime bound |
| 49 | + | |
| 50 | +LL | pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future + '_ { |
| 51 | + | ++++ |
| 52 | + |
| 53 | +error: aborting due to 3 previous errors |
| 54 | + |
| 55 | +Some errors have detailed explanations: E0506, E0700. |
| 56 | +For more information about an error, try `rustc --explain E0506`. |
0 commit comments