Skip to content

Odd Lifetime error when compiling async fn with two non-static and one static reference #76550

@lily-mara

Description

@lily-mara

I tried this code:

struct Foo;

async fn foo(x: &Foo, y: &Foo, z: &'static Foo) {}

I expected to see this happen: The function should compile and be a no-op

Instead, this happened: The code fails to compile with the following error message

error[E0700]: hidden type for `impl Trait` captures lifetime that does not appear in bounds
 --> src/lib.rs:3:49
  |
3 | async fn foo(x: &Foo, y: &Foo, z: &'static Foo) {}
  |                                                 ^
  |

Meta

rustc --version --verbose:

1.46.0

I have reproduced this issue with 1.46.0 as well as nightly 1.48.0 2020-09-08, both in the Rust playground.

Solutions I tried:

Code Summary Result
async fn foo<'a>(x: &'a Foo, y: &'a Foo, z: &'static Foo) {} Constraining x and y to the same lifetime COMPILES
async fn foo(x: &Foo, y: &Foo, z: &Foo) {} removing the static lifetime on z COMPILES
async fn foo(x: &Foo, z: &'static Foo) {} removing x, y, or z COMPILES
async fn foo<'x, 'y>(x: &'x Foo, y: &'y Foo, z: &'static Foo) {} Constraining x and y to independent lifetimes FAILS TO COMPILE
async fn foo<'x, 'y: 'x>(x: &'x Foo, y: &'y Foo, z: &'static Foo) {} Constraining x and y to lifetimes that are not independent COMPILES

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-async-awaitArea: Async & AwaitA-diagnosticsArea: Messages for errors, warnings, and lintsA-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions