Skip to content

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

@lcnr

Description

@lcnr
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.

Metadata

Metadata

Assignees

Labels

A-borrow-checkerArea: The borrow checkerA-diagnosticsArea: Messages for errors, warnings, and lintsA-trait-systemArea: Trait systemD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-hardCall for participation: Hard difficulty. Experience needed to fix: A lot.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.T-typesRelevant to the types 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