Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
lily-mara opened this issue Sep 10, 2020 · 2 comments
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: lifetime related C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lily-mara
Copy link

lily-mara commented Sep 10, 2020

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
@lily-mara lily-mara added the C-bug Category: This is a bug. label Sep 10, 2020
@estebank estebank added A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: lifetime related T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 10, 2020
@SNCPlay42
Copy link
Contributor

SNCPlay42 commented Sep 12, 2020

I think this is a duplicate/another case of #63033.

@jonas-schievink
Copy link
Member

jonas-schievink commented Sep 12, 2020

Indeed, closing as a duplicate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-async-await Area: Async & Await A-diagnostics Area: Messages for errors, warnings, and lints A-lifetimes Area: lifetime related C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants