Skip to content

higher-ranked lifetime error with a simple example involving a BTreeMap #215

Closed
rust-lang/rust
#102680
@ghost

Description

The following (playground)

#[async_trait::async_trait]
trait T {
    async fn f(&self);
}
#[async_trait::async_trait]
// Compiles when the BTreeMap is replaced by a HashMap
impl T for BTreeMap<u32, Box<dyn Send + Sync + 'static>> {
    async fn f(&self) {
        for a in self {
            test().await;
        }
    }
}
async fn test() {}

results in

error: higher-ranked lifetime error
  --> src/lib.rs:11:23
   |
11 |       async fn f(&self) {
   |  _______________________^
12 | |         for a in self {
13 | |             test().await;
14 | |         }
15 | |     }
   | |_____^
   |
   = note: could not prove `for<'r, 's, 't0, 't1, 't2> Pin<Box<impl for<'r, 's, 't0, 't1> Future<Output = ()>>>: CoerceUnsized<Pin<Box<(dyn Future<Output = ()> + Send + 't2)>>>`

however, it works fine when the BTreeMap is replaced by a HashMap.
Might that be an issue with async_trait, or something I misunderstood?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions