Skip to content

async function with default implementation won't compile #17

Open
@rodrigorc

Description

@rodrigorc

I have a trait such as this:

#[trait_variant::make(Test: Send)]
trait LocalTest {
    async fn foo() -> i32 { 0 }
}

but if fails with an error:

  |
3 | #[trait_variant::make(Test: Send)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `{integer}` is not a future
  |

It looks like the body of the default impl is translated to the Test trait, unchanged.

If I instead I try:

    async fn foo() -> i32 { std::future::ready(0) }

Then it looks like the Test works, but LocalTest fails with a somewhat opposite error:

5 |     async fn foo() -> i32 { std::future::ready(0) }
  |                             ^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `Ready<{integer}>`

I'm not sure if this is a limitation of this crate, if so I think it should be documented somewhere; or if it is an oversight in the implementation. Or maybe I'm missing something?

Then, just to see what would happen, I tried:

async fn foo() -> i32 { async move { 0 } }

And I got an ICE!

5 |     async fn foo() -> i32 { async move { 0 } }
  |                             ^^^^^^^^^^^^^^^^ expected `i32`, found `async` block
  |
  = note:       expected type `i32`
          found `async` block `{async block@src/main.rs:5:29: 5:45}`

error: internal compiler error: compiler/rustc_mir_build/src/build/mod.rs:655:72: impossible case reached
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions