Skip to content

.await does not perform autoref or autoderef #111546

Open
@Jules-Bertholet

Description

@Jules-Bertholet

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

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`AsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-bugCategory: This is a bug.T-langRelevant to the language team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & await

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions