forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f22a0c2
commit 61dd81a
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
tests/ui/async-await/lifetime-name-annotation-2021-ice-123420.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
56 changes: 56 additions & 0 deletions
56
tests/ui/async-await/lifetime-name-annotation-2021-ice-123420.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |