rust-lang / rust-lang/rust

"due to current limitations in the borrow checker" is often not a current limitation

Open
#145,347 4 comments 2 reactions 1 assignee View on GitHub

@eval-exec is already working on this.

Since Aug 14, 2025.

A-borrow-checker A-diagnostics A-trait-system D-incorrect E-hard T-compiler T-types
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

fn foo<T>(_: T)
where
    for<'a> T: 'a,
{}

fn main() {
    let local = 1;
    foo(&local);
}

results in

error[E0597]: `local` does not live long enough
 --> src/main.rs:8:9
  |
7 |     let local = 1;
  |         ----- binding `local` declared here
8 |     foo(&local);
  |     ----^^^^^^-
  |     |   |
  |     |   borrowed value does not live long enough
  |     argument requires that `local` is borrowed for `'static`
9 | }
  | - `local` dropped here while still borrowed
  |
note: due to current limitations in the borrow checker, this implies a `'static` lifetime
 --> src/main.rs:3:16
  |
3 |     for<'a> T: 'a,
  |                ^^

This fluent::borrowck_limitations_implies_static note is incorrect. This is not a limitation of our current implementation. local is actually required to be 'static here, regardless of what we do.

It is only a limitation of there would be implied bounds on the bound variable, e.g in for<'a> &'a T: Trait.

We should try to limit the note to such cases. Looking at the affected tests in #145041, most of the places we emit this note actually do not encounter any limitation of the borrowchecker and should continue to error.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.