Skip to content

Wrong Send constraint when using a trait with lifetime + associated type in async #60658

Open
@carllerche

Description

@carllerche

Update: See #60658 (comment) for the latest reproducer

Minimal:

#![feature(async_await, await_macro)]

use std::future::Future;

pub trait Foo<'a> {
    type Future: Future<Output = ()>;
    
    fn foo() -> Self::Future;
}

struct MyType<T>;

impl<'a, T> Foo<'a> for MyType<T>
where
    T: Foo<'a>,
    T::Future: Send,
{
    type Future = Box<Future<Output = ()> + Send>;
    
    fn foo() -> Self::Future {
        Box::new(async move {
            await!(T::foo())
        })
    }
}

fn main() {
}

Out:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
  --> src/main.rs:21:9
   |
21 | /         Box::new(async move {
22 | |             await!(T::foo())
23 | |         })
   | |__________^ one type is more general than the other
   |
   = note: expected type `std::marker::Send`
              found type `std::marker::Send`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

Compiler version: rustc 1.36.0-nightly (2019-05-07)

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsAsyncAwait-TriagedAsync-await issues that have been triaged during a working group meeting.C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    Status

    On deck

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions