Skip to content

Add a help in borrow checker for some strangly early bind closures #164504

Open

Description

@A4-Tacks

Code

fn foo<T: Clone>(ret_type: &T) {
    let f = |_ty| {};
    f(ret_type);
    (|ty| f(&ty))(ret_type.clone());
}

Current output

error[E0597]: `ty` does not live long enough
 --> src/bin/main.rs:4:13
  |
2 |     let f = |_ty| {};
  |         - lifetime `'1` appears in the type of `f`
3 |     f(ret_type);
4 |     (|ty| f(&ty))(ret_type.clone());
  |       --  --^^^-
  |       |   | |  |
  |       |   | |  `ty` dropped here while still borrowed
  |       |   | borrowed value does not live long enough
  |       |   argument requires that `ty` is borrowed for `'1`
  |       binding `ty` declared here

Desired output

error[E0597]: `ty` does not live long enough
 --> src/bin/main.rs:4:13
  |
2 |     let f = |_ty| {};
  |         - lifetime `'1` appears in the type of `f`
3 |     f(ret_type);
4 |     (|ty| f(&ty))(ret_type.clone());
  |       --  --^^^-
  |       |   | |  |
  |       |   | |  `ty` dropped here while still borrowed
  |       |   | borrowed value does not live long enough
  |       |   argument requires that `ty` is borrowed for `'1`
  |       binding `ty` declared here
help: try mark parameter type
  |
2 |     let f = |_ty: &_| {};
  |                 ++++ help: some closure ploblems...

Rationale and extra context

No response

Other cases

Rust Version

rustc 1.101.0-nightly (7df81381d 2026-10-14)
binary: rustc
commit-hash: 7df81381d027710708209f36b98d11b1c88f8d2e
commit-date: 2026-10-14
host: aarch64-unknown-linux-gnu
release: 1.101.0-nightly
LLVM version: 23.1.3

Anything else?

No response

Activity

  1. added
    A-diagnosticsArea: Messages for errors, warnings, and lints
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    on Oct 18, 2026
  2. Muhtasim-Rasheed commented on Oct 18, 2026

    @Muhtasim-Rasheed
    Contributor

    @rustbot claim

  3. added
    D-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.
    A-closuresArea: Closures (`|…| { … }`)
    on Oct 18, 2026
  4. fmease commented on Oct 25, 2026

    @fmease
    Member

    Probably a dupe of #163475, CC #164874 (comment) & #164874 (comment).

  5. Muhtasim-Rasheed commented on Oct 25, 2026

    @Muhtasim-Rasheed
    Contributor

    @rustbot release-assignment

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-closuresArea: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.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