Skip to content
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

Implementation of trait is not general enough when boxing future returning <T as Foo<'a>>::Foo #92415

Open
Tracked by #110338
ibraheemdev opened this issue Dec 29, 2021 · 4 comments
Labels
A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug.

Comments

@ibraheemdev
Copy link
Member

ibraheemdev commented Dec 29, 2021

Reproduction:

use std::any::Any;
use std::future::Future;

trait Foo<'a>: Sized {
    type Error;
    fn foo(x: &'a str) -> Result<Self, Self::Error>;
}

impl<'a> Foo<'a> for &'a str {
    type Error = ();

    fn foo(x: &'a str) -> Result<Self, Self::Error> {
        Ok(x)
    }
}

async fn get_foo<'a, T>(x: &'a str) -> Result<T, <T as Foo<'a>>::Error>
where
    T: Foo<'a>,
{
    Foo::foo(x)
}

fn bar<'a>(x: &'a str) -> Box<dyn Future<Output = Result<&'a str, ()>> + Send + 'a> {
    Box::new(async move { get_foo(x).await })
}

Output on stable and nightly:

error: implementation of `Foo` is not general enough
  --> src/lib.rs:25:5
   |
25 |     Box::new(async move { get_foo(x).await })
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ implementation of `Foo` is not general enough
   |
   = note: `Foo<'1>` would have to be implemented for the type `&'0 str`, for any two lifetimes `'0` and `'1`...
   = note: ...but `Foo<'2>` is actually implemented for the type `&'2 str`, for some specific lifetime `'2

Interestingly, the code compiles without the + Send. It also compiles without the async move block. This may be related to #61949.

@rustbot label +A-async-await

@ibraheemdev ibraheemdev added the C-bug Category: This is a bug. label Dec 29, 2021
@rustbot rustbot added the A-async-await Area: Async & Await label Dec 29, 2021
@compiler-errors
Copy link
Member

This is actually probably related to #60658 (and other issues) instead of #61949, and seems to be fixed under #92449.

@eholk
Copy link
Contributor

eholk commented Jan 10, 2022

This does sound similar to several other issues. Glad to see #92449 seems to fix it.

@rustbot label +AsyncAwait-Triaged +AsyncAwait-Polish

@rustbot rustbot added AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. labels Jan 10, 2022
@vincenzopalazzo
Copy link
Member

@rustbot claim

OK this needs to be fixed in some way, I will try to see what it is going on

@vincenzopalazzo
Copy link
Member

Ah ok this looks like a well-known issue with lifetimes, ok I think this is related to #110338 (comment)

Putting this in our board btw

@vincenzopalazzo vincenzopalazzo removed their assignment Sep 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await AsyncAwait-Polish Async-await issues that are part of the "polish" area AsyncAwait-Triaged Async-await issues that have been triaged during a working group meeting. C-bug Category: This is a bug.
Projects
Status: Claimed
Development

No branches or pull requests

5 participants