Skip to content

Commit a0a9ade

Browse files
authored
Rollup merge of rust-lang#103342 - Rageking8:add-test-for-issue-98634, r=compiler-errors
Add test for issue 98634 Fixes rust-lang#98634
2 parents db43536 + 92b314b commit a0a9ade

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

Diff for: src/test/ui/async-await/issue-98634.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// edition: 2021
2+
3+
use std::{
4+
future::Future,
5+
pin::Pin,
6+
task::{Context, Poll, Waker},
7+
};
8+
9+
pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
10+
pub callback: F,
11+
}
12+
13+
impl<F> Future for StructAsync<F>
14+
where
15+
F: Fn() -> Pin<Box<dyn Future<Output = ()>>>,
16+
{
17+
type Output = ();
18+
19+
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> {
20+
Poll::Pending
21+
}
22+
}
23+
24+
async fn callback() {}
25+
26+
struct Runtime;
27+
28+
fn waker() -> &'static Waker {
29+
todo!()
30+
}
31+
32+
impl Runtime {
33+
#[track_caller]
34+
pub fn block_on<F: Future>(&self, mut future: F) -> F::Output {
35+
loop {
36+
unsafe {
37+
Pin::new_unchecked(&mut future).poll(&mut Context::from_waker(waker()));
38+
}
39+
}
40+
}
41+
}
42+
43+
fn main() {
44+
Runtime.block_on(async {
45+
StructAsync { callback }.await;
46+
//~^ ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
47+
//~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
48+
//~| ERROR expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
49+
});
50+
}

Diff for: src/test/ui/async-await/issue-98634.stderr

+60
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
2+
--> $DIR/issue-98634.rs:45:23
3+
|
4+
LL | StructAsync { callback }.await;
5+
| ^^^^^^^^ expected struct `Pin`, found opaque type
6+
|
7+
note: while checking the return type of the `async fn`
8+
--> $DIR/issue-98634.rs:24:21
9+
|
10+
LL | async fn callback() {}
11+
| ^ checked the `Output` of this `async fn`, found opaque type
12+
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
13+
found opaque type `impl Future<Output = ()>`
14+
note: required by a bound in `StructAsync`
15+
--> $DIR/issue-98634.rs:9:35
16+
|
17+
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
18+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
19+
20+
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
21+
--> $DIR/issue-98634.rs:45:9
22+
|
23+
LL | StructAsync { callback }.await;
24+
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type
25+
|
26+
note: while checking the return type of the `async fn`
27+
--> $DIR/issue-98634.rs:24:21
28+
|
29+
LL | async fn callback() {}
30+
| ^ checked the `Output` of this `async fn`, found opaque type
31+
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
32+
found opaque type `impl Future<Output = ()>`
33+
note: required by a bound in `StructAsync`
34+
--> $DIR/issue-98634.rs:9:35
35+
|
36+
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
38+
39+
error[E0271]: expected `fn() -> impl Future<Output = ()> {callback}` to be a fn item that returns `Pin<Box<(dyn Future<Output = ()> + 'static)>>`, but it returns `impl Future<Output = ()>`
40+
--> $DIR/issue-98634.rs:45:33
41+
|
42+
LL | StructAsync { callback }.await;
43+
| ^^^^^^ expected struct `Pin`, found opaque type
44+
|
45+
note: while checking the return type of the `async fn`
46+
--> $DIR/issue-98634.rs:24:21
47+
|
48+
LL | async fn callback() {}
49+
| ^ checked the `Output` of this `async fn`, found opaque type
50+
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>`
51+
found opaque type `impl Future<Output = ()>`
52+
note: required by a bound in `StructAsync`
53+
--> $DIR/issue-98634.rs:9:35
54+
|
55+
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> {
56+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync`
57+
58+
error: aborting due to 3 previous errors
59+
60+
For more information about this error, try `rustc --explain E0271`.

0 commit comments

Comments
 (0)