Repository navigation
Add a help in borrow checker for some strangly early bind closures #164504
Copy link
Copy link
Open
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
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 hereDesired 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.3Anything else?
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
A-borrow-checkerArea: The borrow checkerArea: The borrow checkerA-closuresArea: Closures (`|…| { … }`)Area: Closures (`|…| { … }`)A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsD-lack-of-suggestionDiagnostics: Adding a (structured) suggestion would increase the quality of the diagnostic.Diagnostics: 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.Relevant to the compiler team, which will review and decide on the PR/issue.
Activity
Muhtasim-Rasheed commentedon Oct 18, 2026
@rustbot claim
fmease commentedon Oct 25, 2026
Probably a dupe of #163475, CC #164874 (comment) & #164874 (comment).
Muhtasim-Rasheed commentedon Oct 25, 2026
@rustbot release-assignment