Skip to content

Commit 3e57b20

Browse files
Add test
1 parent d42a3fb commit 3e57b20

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// run-pass
2+
// edition:2021
3+
4+
#![feature(async_fn_in_trait)]
5+
//~^ WARN the feature `async_fn_in_trait` is incomplete and may not be safe to use
6+
7+
use std::future::Future;
8+
9+
trait AsyncTrait {
10+
async fn default_impl() {
11+
assert!(false);
12+
}
13+
14+
async fn call_default_impl() {
15+
Self::default_impl().await
16+
}
17+
}
18+
19+
struct AsyncType;
20+
21+
impl AsyncTrait for AsyncType {
22+
async fn default_impl() {
23+
// :)
24+
}
25+
}
26+
27+
async fn async_main() {
28+
// Should not assert false
29+
AsyncType::call_default_impl().await;
30+
}
31+
32+
// ------------------------------------------------------------------------- //
33+
// Implementation Details Below...
34+
35+
use std::pin::Pin;
36+
use std::task::*;
37+
38+
pub fn noop_waker() -> Waker {
39+
let raw = RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE);
40+
41+
// SAFETY: the contracts for RawWaker and RawWakerVTable are upheld
42+
unsafe { Waker::from_raw(raw) }
43+
}
44+
45+
const NOOP_WAKER_VTABLE: RawWakerVTable = RawWakerVTable::new(noop_clone, noop, noop, noop);
46+
47+
unsafe fn noop_clone(_p: *const ()) -> RawWaker {
48+
RawWaker::new(std::ptr::null(), &NOOP_WAKER_VTABLE)
49+
}
50+
51+
unsafe fn noop(_p: *const ()) {}
52+
53+
fn main() {
54+
let mut fut = async_main();
55+
56+
// Poll loop, just to test the future...
57+
let waker = noop_waker();
58+
let ctx = &mut Context::from_waker(&waker);
59+
60+
loop {
61+
match unsafe { Pin::new_unchecked(&mut fut).poll(ctx) } {
62+
Poll::Pending => {}
63+
Poll::Ready(()) => break,
64+
}
65+
}
66+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/async-default-fn-overridden.rs:4:12
3+
|
4+
LL | #![feature(async_fn_in_trait)]
5+
| ^^^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)