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

"Parameter type may not live long enough" compilation error for async-fn-in-trait #102682

Closed
bryangarza opened this issue Oct 5, 2022 · 5 comments · Fixed by #105247
Closed
Assignees
Labels
C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits

Comments

@bryangarza
Copy link
Contributor

Encountered in these test cases:

  • async-generics.rs
  • async-generics-and-bounds.rs
  • async-lifetimes-and-bounds.rs

From #102642

Here is async-generics.rs

// edition: 2021

#![feature(async_fn_in_trait)]
#![allow(incomplete_features)]

trait MyTrait<T, U> {
    async fn foo(&self) -> &(T, U);
}
//~^^ ERROR the parameter type `U` may not live long enough
//~| ERROR the parameter type `T` may not live long enough

impl<T, U> MyTrait<T, U> for (T, U) {
    async fn foo(&self) -> &(T, U) {
        self
    }
}

fn main() {}

I expected to see this happen: Successful compilation

Instead, this happened:

error[E0311]: the parameter type `U` may not live long enough
  --> $DIR/async-generics.rs:7:28
   |
LL |     async fn foo(&self) -> &(T, U);
   |                            ^^^^^^^
   |
note: the parameter type `U` must be valid for the anonymous lifetime as defined here...
  --> $DIR/async-generics.rs:7:18
   |
LL |     async fn foo(&self) -> &(T, U);
   |                  ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
  --> $DIR/async-generics.rs:7:28
   |
LL |     async fn foo(&self) -> &(T, U);
   |                            ^^^^^^^

error[E0311]: the parameter type `T` may not live long enough
  --> $DIR/async-generics.rs:7:28
   |
LL |     async fn foo(&self) -> &(T, U);
   |                            ^^^^^^^
   |
note: the parameter type `T` must be valid for the anonymous lifetime as defined here...
  --> $DIR/async-generics.rs:7:18
   |
LL |     async fn foo(&self) -> &(T, U);
   |                  ^
note: ...so that the reference type `&(T, U)` does not outlive the data it points at
  --> $DIR/async-generics.rs:7:28
   |
LL |     async fn foo(&self) -> &(T, U);
   |                            ^^^^^^^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0311`.

Meta

rustc --version --verbose:

rustc 1.66.0-nightly (092255976 2022-10-03)
binary: rustc
commit-hash: 092255976862c1f0121bb4446acd38336a860c4f
commit-date: 2022-10-03
host: x86_64-unknown-linux-gnu
release: 1.66.0-nightly
LLVM version: 15.0.2
@bryangarza bryangarza added the C-bug Category: This is a bug. label Oct 5, 2022
@compiler-errors compiler-errors added the F-async_fn_in_trait Static async fn in traits label Oct 5, 2022
@compiler-errors compiler-errors self-assigned this Oct 5, 2022
@compiler-errors
Copy link
Member

This is probably actually the same issue as the other one, and as #102552 (comment).

@bryangarza
Copy link
Contributor Author

bryangarza commented Oct 7, 2022

Ah, so #102681 and 102552#issuecomment are all the same? Okay, I'm going to use this one as the master one and link it in all 4 tests.

@compiler-errors
Copy link
Member

Yeah, please don't remove the tests but I don't actually know if all of these outlives errors are valid errors or not... best to just lump them into one issue for now.

@compiler-errors
Copy link
Member

Thanks, and sorry for the confusion.

@bryangarza
Copy link
Contributor Author

Gotcha, yeah I'll keep all of the tests in the PR! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-async_fn_in_trait Static async fn in traits
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants