Files
rust/tests/ui/borrowck
Stuart Cook 3e1052c6d5 Rollup merge of #153724 - arferreira:fix-lifetime-naming-in-closures, r=jieyouxu
Show named lifetime in closure upvar diagnostics

Fixes rust-lang/rust#153545.

When a closure captures a variable whose type involves a named lifetime from the parent function (e.g., `'a`), the borrow checker's region renumbering creates a separate `RegionVid` for each occurrence of the erased lifetime in the closure's upvar type. These new `RegionVid`s have no `external_name`, so diagnostics fall back to synthetic names like `'1`.

This PR recovers the original lifetime name by matching the closure's upvar type against the parent function's parameter type (obtained via `liberate_late_bound_regions`). Both types have the same structure but different region representations, the parent has `ReLateParam`/`ReEarlyParam` with real names, the closure has `ReVar` from renumbering. Walking them in parallel with `for_each_free_region` lets us find which named lifetime corresponds to the anonymous `RegionVid`.

Before:

```rust
error[E0716]: temporary value dropped while borrowed
 --> test.rs:11:21
  |
6 | fn apply<'a>(
  |          -- lifetime `'1` defined here
```

After:

```rust
error[E0716]: temporary value dropped while borrowed
 --> test.rs:11:21
  |
6 | fn apply<'a>(
  |          -- lifetime `'a` defined here
```

The fix gracefully falls back to the existing `'1` naming when it can't match, nested closures, local variables (not parameters), destructuring patterns, or partial captures where the type structures diverge.
2026-03-16 15:01:34 +11:00
..
2025-08-27 00:23:26 -04:00
2026-02-04 04:45:52 +00:00
2025-11-27 14:13:58 -05:00
2024-04-11 16:41:41 +00:00
2024-04-11 16:41:41 +00:00
2025-11-27 14:13:58 -05:00
2025-11-27 14:13:58 -05:00
2025-07-25 20:38:54 +05:00
2025-07-25 20:38:54 +05:00
2025-09-28 20:55:35 +00:00
2025-09-28 20:55:35 +00:00
2024-07-04 04:36:52 +00:00
2025-06-06 21:27:37 -04:00
2025-01-28 19:35:51 +00:00
2024-02-20 15:34:11 +01:00
2024-02-20 15:34:11 +01:00
2025-07-31 21:25:49 +05:00
2025-07-31 21:25:49 +05:00