Fix drop shim for AsyncFnOnce closure, AsyncFnMut shim for AsyncFn closure
This commit is contained in:
parent
c98d6994a3
commit
ca44416023
35 changed files with 595 additions and 67 deletions
|
@ -0,0 +1,23 @@
|
|||
// aux-build:block-on.rs
|
||||
// edition:2021
|
||||
// run-pass
|
||||
|
||||
// FIXME(async_closures): When `fn_sig_for_fn_abi` is fixed, remove this.
|
||||
// ignore-pass (test emits codegen-time warnings)
|
||||
|
||||
#![feature(async_closure, async_fn_traits)]
|
||||
|
||||
extern crate block_on;
|
||||
|
||||
use std::ops::AsyncFnMut;
|
||||
|
||||
fn main() {
|
||||
block_on::block_on(async {
|
||||
let x = async || {};
|
||||
|
||||
async fn needs_async_fn_mut(mut x: impl AsyncFnMut()) {
|
||||
x().await;
|
||||
}
|
||||
needs_async_fn_mut(x).await;
|
||||
});
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
WARN rustc_codegen_ssa::mir::locals Unexpected initial operand type: expected std::pin::Pin<&ReErased mut Coroutine(DefId(0:8 ~ async_fn_mut_for_async_fn[3241]::main::{closure#0}::{closure#0}::{closure#0}), [i16, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_mut_for_async_fn[3241]::main::{closure#0}::{closure#0}::{closure#0}), []), ()])>, found std::pin::Pin<&ReErased mut Coroutine(DefId(0:8 ~ async_fn_mut_for_async_fn[3241]::main::{closure#0}::{closure#0}::{closure#0}), [i8, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_mut_for_async_fn[3241]::main::{closure#0}::{closure#0}::{closure#0}), []), ()])>.See <https://github.com/rust-lang/rust/issues/114858>.
|
|
@ -1,2 +1 @@
|
|||
WARN rustc_codegen_ssa::mir::locals Unexpected initial operand type: expected std::pin::Pin<&ReErased mut Coroutine(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), [i32, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), []), ()])>, found std::pin::Pin<&ReErased mut Coroutine(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), [i8, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), []), ()])>.See <https://github.com/rust-lang/rust/issues/114858>.
|
||||
WARN rustc_codegen_ssa::mir::locals Unexpected initial operand type: expected *mut Coroutine(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), [i8, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), []), ()]), found *mut Coroutine(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), [i32, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#1}), []), ()]).See <https://github.com/rust-lang/rust/issues/114858>.
|
||||
WARN rustc_codegen_ssa::mir::locals Unexpected initial operand type: expected std::pin::Pin<&ReErased mut Coroutine(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#0}::{closure#0}), [i32, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#0}::{closure#0}), []), ()])>, found std::pin::Pin<&ReErased mut Coroutine(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#0}::{closure#0}), [i8, std::future::ResumeTy, (), (), CoroutineWitness(DefId(0:8 ~ async_fn_once_for_async_fn[6cdf]::main::{closure#0}::{closure#0}::{closure#0}), []), ()])>.See <https://github.com/rust-lang/rust/issues/114858>.
|
||||
|
|
|
@ -8,7 +8,7 @@ fn main() {
|
|||
//~^ NOTE the expected `async` closure body
|
||||
let () = x();
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE this expression has type `{static main::{closure#0}::{closure#0} upvar_tys=
|
||||
//~| NOTE this expression has type `{static main::{closure#0}::{closure#0}<
|
||||
//~| NOTE expected `async` closure body, found `()`
|
||||
//~| NOTE expected `async` closure body `{static main::{closure#0}::{closure#0}
|
||||
//~| NOTE expected `async` closure body `{static main::{closure#0}::{closure#0}<
|
||||
}
|
||||
|
|
|
@ -5,11 +5,11 @@ LL | let x = async || {};
|
|||
| -- the expected `async` closure body
|
||||
LL |
|
||||
LL | let () = x();
|
||||
| ^^ --- this expression has type `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}`
|
||||
| ^^ --- this expression has type `{static main::{closure#0}::{closure#0}<?7t> upvar_tys=?15t witness=?6t}`
|
||||
| |
|
||||
| expected `async` closure body, found `()`
|
||||
|
|
||||
= note: expected `async` closure body `{static main::{closure#0}::{closure#0} upvar_tys=?7t witness=?8t}`
|
||||
= note: expected `async` closure body `{static main::{closure#0}::{closure#0}<?7t> upvar_tys=?15t witness=?6t}`
|
||||
found unit type `()`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
|
40
tests/ui/async-await/async-closures/drop.rs
Normal file
40
tests/ui/async-await/async-closures/drop.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
// aux-build:block-on.rs
|
||||
// edition:2018
|
||||
// run-pass
|
||||
// check-run-results
|
||||
|
||||
#![feature(async_closure, async_fn_traits)]
|
||||
#![allow(unused)]
|
||||
|
||||
extern crate block_on;
|
||||
|
||||
use std::ops::AsyncFnOnce;
|
||||
|
||||
struct DropMe(i32);
|
||||
|
||||
impl Drop for DropMe {
|
||||
fn drop(&mut self) {
|
||||
println!("{} was dropped", self.0);
|
||||
}
|
||||
}
|
||||
|
||||
async fn call_once(f: impl AsyncFnOnce()) {
|
||||
println!("before call");
|
||||
let fut = Box::pin(f());
|
||||
println!("after call");
|
||||
drop(fut);
|
||||
println!("future dropped");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
block_on::block_on(async {
|
||||
let d = DropMe(42);
|
||||
let async_closure = async move || {
|
||||
let d = &d;
|
||||
println!("called");
|
||||
};
|
||||
|
||||
call_once(async_closure).await;
|
||||
println!("after");
|
||||
});
|
||||
}
|
5
tests/ui/async-await/async-closures/drop.run.stdout
Normal file
5
tests/ui/async-await/async-closures/drop.run.stdout
Normal file
|
@ -0,0 +1,5 @@
|
|||
before call
|
||||
after call
|
||||
42 was dropped
|
||||
future dropped
|
||||
after
|
36
tests/ui/async-await/async-closures/mangle.rs
Normal file
36
tests/ui/async-await/async-closures/mangle.rs
Normal file
|
@ -0,0 +1,36 @@
|
|||
// aux-build:block-on.rs
|
||||
// edition:2021
|
||||
// build-pass
|
||||
// revisions: v0 legacy
|
||||
//[v0] compile-flags: -Csymbol-mangling-version=v0
|
||||
//[legacy] compile-flags: -Csymbol-mangling-version=legacy -Zunstable-options
|
||||
|
||||
// FIXME(async_closures): When `fn_sig_for_fn_abi` is fixed, remove this.
|
||||
// ignore-pass (test emits codegen-time warnings)
|
||||
|
||||
#![feature(async_closure, noop_waker, async_fn_traits)]
|
||||
|
||||
extern crate block_on;
|
||||
|
||||
use std::future::Future;
|
||||
use std::ops::{AsyncFnMut, AsyncFnOnce};
|
||||
use std::pin::pin;
|
||||
use std::task::*;
|
||||
|
||||
async fn call_mut(f: &mut impl AsyncFnMut()) {
|
||||
f().await;
|
||||
}
|
||||
|
||||
async fn call_once(f: impl AsyncFnOnce()) {
|
||||
f().await;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
block_on::block_on(async {
|
||||
let mut async_closure = async move || {
|
||||
println!("called");
|
||||
};
|
||||
call_mut(&mut async_closure).await;
|
||||
call_once(async_closure).await;
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue