Skip to content

Commit

Permalink
add test for rust-lang#123420
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiaskrgr committed Apr 21, 2024
1 parent f22a0c2 commit 61dd81a
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/ui/async-await/lifetime-name-annotation-2021-ice-123420.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// issue rust-lang/rust#123420
// ICE assertion failed: i32 != &'{erased} mut i32
//@ edition:2021
#![feature(async_closure)]
use std::future::Future;

pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future {
(async move || -> &i32 {
//~^ ERROR lifetime may not live long enough
//~| ERROR hidden type for `impl Future` captures lifetime that does not appear in bounds
let y = &*x;
*x += 1;
//~^ ERROR cannot assign to `*x` because it is borrowed
y
})()
}

pub fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
error[E0506]: cannot assign to `*x` because it is borrowed
--> $DIR/lifetime-name-annotation-2021-ice-123420.rs:12:9
|
LL | let y = &*x;
| --- `*x` is borrowed here
LL | *x += 1;
| ^^^^^^^ `*x` is assigned to here but it was already borrowed
LL |
LL | y
| - returning this value requires that `*x` is borrowed for `'1`
LL | })()
| - return type of async closure is &'1 i32

error: lifetime may not live long enough
--> $DIR/lifetime-name-annotation-2021-ice-123420.rs:8:28
|
LL | (async move || -> &i32 {
| ______---------------------_^
| | | |
| | | return type of async closure `{async closure body@$DIR/lifetime-name-annotation-2021-ice-123420.rs:8:28: 15:6}` contains a lifetime `'2`
| | lifetime `'1` represents this closure's body
LL | |
LL | |
LL | | let y = &*x;
... |
LL | | y
LL | | })()
| |_____^ returning this value requires that `'1` must outlive `'2`
|
= note: closure implements `FnMut`, so references to captured variables can't escape the closure

error[E0700]: hidden type for `impl Future` captures lifetime that does not appear in bounds
--> $DIR/lifetime-name-annotation-2021-ice-123420.rs:8:5
|
LL | pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future {
| -------- ----------- opaque type defined here
| |
| hidden type `{async closure body@$DIR/lifetime-name-annotation-2021-ice-123420.rs:8:28: 15:6}` captures the anonymous lifetime defined here
LL | / (async move || -> &i32 {
LL | |
LL | |
LL | | let y = &*x;
... |
LL | | y
LL | | })()
| |________^
|
help: to declare that `impl Future` captures `'_`, you can add an explicit `'_` lifetime bound
|
LL | pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future + '_ {
| ++++

error: aborting due to 3 previous errors

Some errors have detailed explanations: E0506, E0700.
For more information about an error, try `rustc --explain E0506`.

0 comments on commit 61dd81a

Please sign in to comment.