Skip to content

Commit 61dd81a

Browse files
committed
add test for rust-lang#123420
1 parent f22a0c2 commit 61dd81a

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// issue rust-lang/rust#123420
2+
// ICE assertion failed: i32 != &'{erased} mut i32
3+
//@ edition:2021
4+
#![feature(async_closure)]
5+
use std::future::Future;
6+
7+
pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future {
8+
(async move || -> &i32 {
9+
//~^ ERROR lifetime may not live long enough
10+
//~| ERROR hidden type for `impl Future` captures lifetime that does not appear in bounds
11+
let y = &*x;
12+
*x += 1;
13+
//~^ ERROR cannot assign to `*x` because it is borrowed
14+
y
15+
})()
16+
}
17+
18+
pub fn main() {}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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

Comments
 (0)