Skip to content

multiple spurious errors when T: 'static is required in async fn #115376

Closed

Description

@aliemjay

Given this code:

async fn test<T>(_: &u8) {
    let _: &'static T;
    //~^ ERROR the parameter type `T` may not live long enough
    //~| ERROR the parameter type `T` may not live long enough
}

Two errors are emitted: one requires T: 'static, as expected, and the other requires T: 'a where 'a is the anonymous lifetime.

This affects lifetime constraints that originate in async fn, async blocks, and closures.

An error is emitted for each lifetime that appears in the function because 'static is an upper bound for all lifetimes.

error[E0310]: the parameter type `T` may not live long enough
 --> src/lib.rs:2:12
  |
2 |     let _: &'static T;
  |            ^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
  |
help: consider adding an explicit lifetime bound...
  |
1 | async fn test<T: 'static>(_: &u8) {
  |                +++++++++

error[E0311]: the parameter type `T` may not live long enough
 --> src/lib.rs:2:12
  |
2 |     let _: &'static T;
  |            ^^^^^^^^^^
  |
note: the parameter type `T` must be valid for the anonymous lifetime defined here...
 --> src/lib.rs:1:21
  |
1 | async fn test<T>(_: &u8) {
  |                     ^^^
note: ...so that the type `T` will meet its required lifetime bounds
 --> src/lib.rs:2:12
  |
2 |     let _: &'static T;
  |            ^^^^^^^^^^
help: consider adding an explicit lifetime bound...
  |
1 | async fn test<'a, T: 'a>(_: &'a u8) {
  |               +++  ++++      ++

Activity

  1. added
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 30, 2023
  2. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    C-bugCategory: This is a bug.
    D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Aug 30, 2023
  3. Enselic commented on Mar 25, 2026

    @Enselic
    Member

    Triage: To avoid any misunderstanding, would you mind elaborating on what output you expect to see, and not only what you actually see? Thanks!

    Here is the current output:

    $ rustc +nightly-2026-03-01 --crate-type lib /home/martin/src/lib.rs --edition 2021
    error[E0310]: the parameter type `T` may not live long enough
     --> /home/martin/src/lib.rs:2:12
      |
    2 |     let _: &'static T;
      |            ^^^^^^^^^^
      |            |
      |            the parameter type `T` must be valid for the static lifetime...
      |            ...so that the type `T` will meet its required lifetime bounds
      |
    help: consider adding an explicit lifetime bound
      |
    1 | async fn test<T: 'static>(_: &u8) {
      |                +++++++++
    
    error[E0311]: the parameter type `T` may not live long enough
     --> /home/martin/src/lib.rs:2:12
      |
    1 | async fn test<T>(_: &u8) {
      |                     --- the parameter type `T` must be valid for the anonymous lifetime defined here...
    2 |     let _: &'static T;
      |            ^^^^^^^^^^ ...so that the type `T` will meet its required lifetime bounds
      |
    help: consider adding an explicit lifetime bound
      |
    1 | async fn test<'a, T: 'a>(_: &'a u8) {
      |               +++  ++++      ++
    
    error: aborting due to 2 previous errors
    
    Some errors have detailed explanations: E0310, E0311.
    For more information about an error, try `rustc --explain E0310`.
  4. added 3 commits that reference this issue on Sep 7, 2026
    b2d7624
    eb3c2a4
    89309f2
  5. added a commit that references this issue on Sep 7, 2026
    c67df82
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-borrow-checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsC-bugCategory: This is a bug.D-verboseDiagnostics: Too much output caused by a single piece of incorrect code.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