Provide help on closures capturing self
causing borrow checker errors
#105761
Labels
A-borrow-checker
Area: The borrow checker
A-closures
Area: Closures (`|…| { … }`)
A-diagnostics
Area: Messages for errors, warnings, and lints
A-suggestion-diagnostics
Area: Suggestions generated by the compiler applied by `cargo fix`
D-newcomer-roadblock
Diagnostics: Confusing error or lint; hard to understand for new users.
D-papercut
Diagnostics: An error or lint that needs small tweaks.
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
Given a closure that immutably captures
self
, you can easily cause a lifetime errorThe usual solution here is to explicitly pass
self
into the closure as anthis: &Self
argument to side-step the issue. We should suggest doing so.The text was updated successfully, but these errors were encountered: