rust/tests/ui/async-await/in-trait/async-default-fn-overridden.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
953 B
Rust
Raw Normal View History

2023-01-17 23:48:26 +00:00
//@ run-pass
//@ edition:2021
2023-12-14 18:34:29 +00:00
#![feature(noop_waker)]
2023-01-17 23:48:26 +00:00
use std::future::Future;
trait AsyncTrait {
2023-09-26 20:20:25 +00:00
#[allow(async_fn_in_trait)]
2023-01-17 23:48:26 +00:00
async fn default_impl() {
assert!(false);
}
2023-09-26 20:20:25 +00:00
#[allow(async_fn_in_trait)]
2023-01-17 23:48:26 +00:00
async fn call_default_impl() {
Self::default_impl().await
}
}
struct AsyncType;
impl AsyncTrait for AsyncType {
async fn default_impl() {
// :)
}
}
async fn async_main() {
// Should not assert false
AsyncType::call_default_impl().await;
}
// ------------------------------------------------------------------------- //
// Implementation Details Below...
2023-12-14 18:34:29 +00:00
use std::pin::pin;
2023-01-17 23:48:26 +00:00
use std::task::*;
fn main() {
2023-12-14 18:34:29 +00:00
let mut fut = pin!(async_main());
2023-01-17 23:48:26 +00:00
// Poll loop, just to test the future...
let ctx = &mut Context::from_waker(Waker::noop());
2023-01-17 23:48:26 +00:00
loop {
2023-12-14 18:34:29 +00:00
match fut.as_mut().poll(ctx) {
2023-01-17 23:48:26 +00:00
Poll::Pending => {}
Poll::Ready(()) => break,
}
}
}