-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Add test for issue 98634 #103342
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+110
−0
Merged
Add test for issue 98634 #103342
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,50 @@ | ||
// edition: 2021 | ||
|
||
use std::{ | ||
future::Future, | ||
pin::Pin, | ||
task::{Context, Poll, Waker}, | ||
}; | ||
|
||
pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> { | ||
pub callback: F, | ||
} | ||
|
||
impl<F> Future for StructAsync<F> | ||
where | ||
F: Fn() -> Pin<Box<dyn Future<Output = ()>>>, | ||
{ | ||
type Output = (); | ||
|
||
fn poll(self: Pin<&mut Self>, _cx: &mut Context<'_>) -> Poll<Self::Output> { | ||
Poll::Pending | ||
} | ||
} | ||
|
||
async fn callback() {} | ||
|
||
struct Runtime; | ||
|
||
fn waker() -> &'static Waker { | ||
todo!() | ||
} | ||
|
||
impl Runtime { | ||
#[track_caller] | ||
pub fn block_on<F: Future>(&self, mut future: F) -> F::Output { | ||
loop { | ||
unsafe { | ||
Pin::new_unchecked(&mut future).poll(&mut Context::from_waker(waker())); | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn main() { | ||
Runtime.block_on(async { | ||
StructAsync { callback }.await; | ||
//~^ 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 = ()>` | ||
//~| 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 = ()>` | ||
//~| 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 = ()>` | ||
}); | ||
} |
This file contains hidden or 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,60 @@ | ||
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 = ()>` | ||
--> $DIR/issue-98634.rs:45:23 | ||
| | ||
LL | StructAsync { callback }.await; | ||
| ^^^^^^^^ expected struct `Pin`, found opaque type | ||
| | ||
note: while checking the return type of the `async fn` | ||
--> $DIR/issue-98634.rs:24:21 | ||
| | ||
LL | async fn callback() {} | ||
| ^ checked the `Output` of this `async fn`, found opaque type | ||
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>` | ||
found opaque type `impl Future<Output = ()>` | ||
note: required by a bound in `StructAsync` | ||
--> $DIR/issue-98634.rs:9:35 | ||
| | ||
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` | ||
|
||
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 = ()>` | ||
--> $DIR/issue-98634.rs:45:9 | ||
| | ||
LL | StructAsync { callback }.await; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ expected struct `Pin`, found opaque type | ||
| | ||
note: while checking the return type of the `async fn` | ||
--> $DIR/issue-98634.rs:24:21 | ||
| | ||
LL | async fn callback() {} | ||
| ^ checked the `Output` of this `async fn`, found opaque type | ||
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>` | ||
found opaque type `impl Future<Output = ()>` | ||
note: required by a bound in `StructAsync` | ||
--> $DIR/issue-98634.rs:9:35 | ||
| | ||
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` | ||
|
||
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 = ()>` | ||
--> $DIR/issue-98634.rs:45:33 | ||
| | ||
LL | StructAsync { callback }.await; | ||
| ^^^^^^ expected struct `Pin`, found opaque type | ||
| | ||
note: while checking the return type of the `async fn` | ||
--> $DIR/issue-98634.rs:24:21 | ||
| | ||
LL | async fn callback() {} | ||
| ^ checked the `Output` of this `async fn`, found opaque type | ||
= note: expected struct `Pin<Box<(dyn Future<Output = ()> + 'static)>>` | ||
found opaque type `impl Future<Output = ()>` | ||
note: required by a bound in `StructAsync` | ||
--> $DIR/issue-98634.rs:9:35 | ||
| | ||
LL | pub struct StructAsync<F: Fn() -> Pin<Box<dyn Future<Output = ()>>>> { | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ required by this bound in `StructAsync` | ||
|
||
error: aborting due to 3 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0271`. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.