-
Notifications
You must be signed in to change notification settings - Fork 9
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
async function with default implementation won't compile #17
Comments
Also ran into this. I have a trait with this function and a default body: async fn is_version_supported(&self, req: &str) -> miette::Result<bool> {
let version = self.get_version().await?;
Ok(VersionReq::parse(req).into_diagnostic()?.matches(&version))
} This fails to compile with:
When looking at the #[doc = r" Return true if the current binary version matches the provided requirement."]
fn is_version_supported(
&self,
req: &str,
) -> impl ::core::future::Future<Output = miette::Result<bool>> + Send {
let version = self.get_version().await?;
Ok(VersionReq::parse(req).into_diagnostic()?.matches(&version))
} |
I almost had opened an issue with the same problem with title, "making a variant with ==== The issue body ==== Adding pub trait LocalTest {
async fn test(&self) -> String {
panic!()
}
} rustc: `()` is not a future
the trait `std::future::Future` is not implemented for `()`
() must be a future or must implement `IntoFuture` to be awaited [E0277] Macros that desugar
As the user side, I cannot find a way to work around this, especially when using the Related: |
It’s not silky smooth to use for me also. However, I could give a relatively silky example. #[trait_variant::make(Test: Send)]
trait LocalTest {
// Below can not work (`Result<(), _>` is not a future)
// async fn foo() -> anyhow::Result<()> {
// Ok(())
// }
// Below can work
fn foo() -> impl core::future::Future<Output = anyhow::Result<()>> {
async { Ok(()) }
}
async fn bar() -> anyhow::Result<()>;
async fn baz() -> anyhow::Result<()>;
}
struct Foo;
impl LocalTest for Foo {
async fn foo() -> anyhow::Result<()> {
Ok(())
}
async fn bar() -> anyhow::Result<()> {
Ok(())
}
async fn baz() -> anyhow::Result<()> {
todo!()
}
}
struct Bar;
impl Test for Bar {
async fn foo() -> anyhow::Result<()> {
Ok(())
}
async fn bar() -> anyhow::Result<()> {
Ok(())
}
async fn baz() -> anyhow::Result<()> {
todo!()
}
} To conclude,
|
I gave both PRs a shot in a code base where I encountered this issue which involved lifetimes and #28 worked while with #20 I two errors where the lifetime 'the_self_lt needed to outlive 'static and that the implementation of Send is not general enough. I have not been successful at creating a simpler example so sry I can't provide one. |
@AlvaroSierra I'm surprised #28 worked with your example, I couldn't get it to compile without adding |
@tmandry In my case, where the self is taken as |
I have a trait such as this:
but if fails with an error:
It looks like the body of the default impl is translated to the
Test
trait, unchanged.If I instead I try:
Then it looks like the
Test
works, butLocalTest
fails with a somewhat opposite error: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:
And I got an ICE!
The text was updated successfully, but these errors were encountered: