Simple Async Fn Fails to Compile Due to Lifetime Error

Below is an async fn that does not compile:

async fn trouble(_: &str, _: &str, _: &'static str) {}

with message:

error[E0700]: hidden type for impl Trait captures lifetime that does not appear in bounds

But the problem disappears as soon as we change the signature. All of the following are good:

async fn ok_str_str(_: &str, _: &str) {}
async fn ok_str_str_str(_: &str, _: &str, _: &str) {}
async fn ok_str_static(_: &str, _: &'static str) {}
async fn ok_str_static_static(_: &str, _: &'static str, _: &'static str) {}

fn ok_str_str_static_desugar(_: &str, _: &str, _: &'static str) -> impl Future<Output = ()> {
    async { () }

Why is this happening? Playground link.

This looks like a bug, and indeed there is a bug report for it!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.