Skip to content

coroutine higher-ranked auto trait errors should point at the definition whose bound vars are part of the error #155880

@lcnr

Description

@lcnr
trait Trait {
    type Assoc<'a>
    where
        Self: 'a;
}

impl<T> Trait for T {
    type Assoc<'a> = ()
    where
        Self: 'a;
}

async fn inner<'a, T: Trait + 'a>(_: T, x: T::Assoc<'a>) -> T::Assoc<'a> {
    std::future::ready(x).await
}

async fn outer<'a>() {
    let x = 1u32;
    inner(&x, ()).await;
}

fn is_send<T: Send>(_: T) {}

fn main() {
    is_send(outer())
}

this results in

error: implementation of `Send` is not general enough
  --> src/main.rs:25:5
   |
25 |     is_send(outer())
   |     ^^^^^^^^^^^^^^^^ implementation of `Send` is not general enough
   |
   = note: `Send` would have to be implemented for the type `&'0 u32`, for any lifetime `'0`...
   = note: ...but `Send` is actually implemented for the type `&'1 u32`, for some specific lifetime `'1`

fixing the underlying issue may still take a while, we should at least point to the source of the coroutine which introduces that '0 and '1 in the error, i.e. I expect that we can fairly easily point at the body of inner here

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-auto-traitsArea: auto traits (e.g., `auto trait Send {}`)A-coroutinesArea: CoroutinesA-diagnosticsArea: Messages for errors, warnings, and lintsA-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.WG-asyncWorking group: Async & await

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions