Skip to content

Mysterious "higher-ranked lifetime error" with async fn in trait and return-type notation #110963

@compiler-errors

Description

@compiler-errors

I tried this code:

#![feature(return_type_notation)] #![feature(async_fn_in_trait)] trait HealthCheck { async fn check<'a: 'a>(&'a mut self) -> bool; } async fn do_health_check_par<HC>(hc: HC) where HC: HealthCheck<check(): Send> + Send + 'static, { tokio::task::spawn(async move { let mut hc = hc; if !hc.check().await { log_health_check_failure().await; } }); } async fn log_health_check_failure() {}

I expected to see this happen: it works

Instead, this happened:

error: higher-ranked lifetime error --> src/lib.rs:12:5 | 12 | / tokio::task::spawn(async move { 13 | | let mut hc = hc; 14 | | if !hc.check().await { 15 | | log_health_check_failure().await; 16 | | } 17 | | }); | |______^ | = note: could not prove `[async block@src/lib.rs:12:24: 17:6]: Send` 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-NLLArea: Non-lexical lifetimes (NLL)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)C-bugCategory: This is a bug.D-confusingDiagnostics: Confusing error or lint that should be reworked.F-async_fn_in_traitStatic async fn in traitsF-return_type_notation`#[feature(return_type_notation)]`T-typesRelevant to the types team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.

    Type

    No type

    Projects

    Status

    Non-blocking

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions