-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await
Description
I tried this code:
use core::future::IntoFuture;
use futures::future::{ready, Ready};
struct Foo;
impl IntoFuture for &Foo {
type Output = u32;
type IntoFuture = Ready<u32>;
fn into_future(self) -> Self::IntoFuture {
ready(2)
}
}
#[tokio::main]
async fn main() {
assert_eq!(Foo.await, 2);
}
I expected to see this happen: Compiles and runs successfully. The .await
performs auto-ref, and <&Foo as IntoFuture>::into_future()
is called.
Instead, this happened:
error[E0277]: `Foo` is not a future
--> src/main.rs:16:19
|
16 | assert_eq!(Foo.await, 2);
| ^^^^^^
| |
| `Foo` is not a future
| help: remove the `.await`
|
= help: the trait `futures::Future` is not implemented for `Foo`
= note: Foo must be a future or must implement `IntoFuture` to be awaited
= help: the trait `std::future::IntoFuture` is implemented for `&Foo`
= note: required for `Foo` to implement `std::future::IntoFuture`
Meta
rustc --version --verbose
:
1.71.0-nightly (2023-05-12 4a59ba4d54a3ec0d8ea1)
@rustbot label A-async-await
Metadata
Metadata
Assignees
Labels
A-async-awaitArea: Async & AwaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.Async-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.Category: This is a bug.T-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & awaitWorking group: Async & await