diagnostics: Suggest fn binding type for unstable closure for<> binders - #160478
Draft
Dnreikronos wants to merge 2 commits into
Draft
diagnostics: Suggest fn binding type for unstable closure for<> binders#160478Dnreikronos wants to merge 2 commits into
Dnreikronos wants to merge 2 commits into
Conversation
Collaborator
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
Collaborator
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
When `for<'a>` appears on a closure without `closure_lifetime_binder`, suggest rewriting a simple let-bound closure to a stable `for<'a> fn(...)` binding type annotation when that rewrite is safe. Co-authored-by: Cursor <cursoragent@cursor.com>
Cover MachineApplicable rewrites, MaybeIncorrect capture cases, and macro-expanded binders where structured suggestions must be suppressed. Co-authored-by: Cursor <cursoragent@cursor.com>
Dnreikronos
force-pushed
the
diagnostics/closure_lifetime_binder_sugg
branch
from
August 4, 2026 01:38
b3e5c81 to
8a03a04
Compare
Dnreikronos
marked this pull request as draft
August 4, 2026 01:42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #160431
for<'a> |x: &'a T| -> U { ... }currently just says "consider removing for<...>", which idk is kinda useless when someone landed there while fighting HRTB errors. This rewrites the obvious case tolet cl: for<'a> fn(...) = |x| { ... }instead.Visitor emits the gate so we have AST context for the rewrite, and we still keep a pre-expansion fallback for
#[cfg(false)]etc. MachineApplicable only when we're pretty sure: by-value bindings, lifetime-only unbounded binders, no_in the sig, no macro expansion. Capture checking is a conservative single-segment free-path heuristic since this runs pre-resolution/pre-typeck; when that looks uncertain we fall back to MaybeIncorrect (or just "consider removing"). imo that's the right tradeoff here: better a maybe-wrong help than rustfix auto-applying into E0308. fyi free-fn /None/Somecases also hit MaybeIncorrect for the same reason.ltm if the heuristic feels too conservative and y'all want it tightened later.