dtolnay / async-trait

Type erasure for async trait methods
Apache License 2.0
1.81k stars 84 forks source link

Could not find `future` in `core` #109

Closed alex-dukhno closed 4 years ago

alex-dukhno commented 4 years ago

Hi there,

I've got the following case:

// crate `interface`
#[async_trait]
pub trait MyInterface {
  async fn function() -> Result<(), Error>;
}

// crate `implementation`
pub struct Implementation;

#[async_trait]
impl MyInterface for Implementation {
  async fn function() -> Result<(), Error> {
    Ok(())
  }
}

when I compiling the project I got the following compiler error:

error[E0433]: failed to resolve: could not find `pin` in `core`
  --> src/node/src/query_listener.rs:32:1
   |
32 | #[async_trait]
   | ^^^^^^^^^^^^^^ could not find `pin` in `core`

error[E0433]: failed to resolve: could not find `future` in `core`
  --> src/node/src/query_listener.rs:32:1
   |
32 | #[async_trait]
   | ^^^^^^^^^^^^^^ could not find `future` in `core`

error[E0433]: failed to resolve: could not find `marker` in `core`
  --> src/node/src/query_listener.rs:32:1
   |
32 | #[async_trait]
   | ^^^^^^^^^^^^^^ could not find `marker` in `core`

Thank you

dtolnay commented 4 years ago

Can you provide a minimal git repo or something which I could cargo build to reproduce this?

alex-dukhno commented 4 years ago

Hi, thank you for quick response.

Seems like the case is much more complicated then I thought ... I created repo https://github.com/alex-dukhno/async-trait-cross-crates-compilation, but I couldn't reproduce the exact error ... but I got the other ... Trait has Self::Item return value in https://github.com/alex-dukhno/async-trait-cross-crates-compilation/blob/master/src/interface/src/lib.rs#L9 but I had to return reference in impl https://github.com/alex-dukhno/async-trait-cross-crates-compilation/blob/master/src/implementation/src/some_module.rs#L14 otherwise I got compilation error

error[E0053]: method `item` has an incompatible type for trait
  --> src/implementation/src/some_module.rs:14:5
   |
14 |     fn item(&self) -> Self::Item {
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `&some_module::OtherImplementation`, found struct `some_module::OtherImplementation`
   |
   = note: expected fn pointer `fn(&some_module::Implementation) -> &some_module::OtherImplementation`
              found fn pointer `fn(&some_module::Implementation) -> some_module::OtherImplementation`

I don't know if it suits you but I can give you a link to the branch of my repo where original problem can be reproduced. Here it is https://github.com/alex-dukhno/database/tree/initial-extraction-of-api-for-pg-wire-protocol

dtolnay commented 4 years ago

It looks like you've provided your own implementation of core here which has an API that is different from libcore (https://doc.rust-lang.org/core/). Similar to std, core is reserved in Rust to refer to crates which provide the API of libcore, so I am not surprised that it leads to problems. I'll close this issue since a nonstandard libcore is not a setup that we could support.

alex-dukhno commented 4 years ago

Thanks. Then I’ll rename the create