diagnostics: Suggest fn binding type for unstable closure for<> binders - #160478
diagnostics: Suggest fn binding type for unstable closure for<> binders#160478Dnreikronos wants to merge 2 commits into
Conversation
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
|
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.
b3e5c81 to
8a03a04
Compare
This comment has been minimized.
This comment has been minimized.
8a03a04 to
1fccd4c
Compare
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>
1fccd4c to
7b0d9e4
Compare
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
This looks cool but I might not have time to review this in the next 2 weeks as it would require me to do some reading about how |
|
I will do a perf run, just in case, since this does some extra work |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
…er_sugg, r=<try> diagnostics: Suggest fn binding type for unstable closure for<> binders
This comment has been minimized.
This comment has been minimized.
|
Finished benchmarking commit (44fa895): comparison URL. Overall result: no relevant changes - no action neededBenchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up. @rustbot label: -S-waiting-on-perf -perf-regression Instruction countThis perf run didn't have relevant results for this metric. Max RSS (memory usage)Results (secondary -0.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (primary 2.6%, secondary -0.2%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Bootstrap: 455.478s -> 454.351s (-0.25%) |
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.