Skip to content

fix: flatten nested HRTB predicate binders - #23139

Open
YUZHEthefool wants to merge 1 commit into
rust-lang:masterfrom
YUZHEthefool:fix/nested-hrtb-predicate-binders
Open

fix: flatten nested HRTB predicate binders#23139
YUZHEthefool wants to merge 1 commit into
rust-lang:masterfrom
YUZHEthefool:fix/nested-hrtb-predicate-binders

Conversation

@YUZHEthefool

@YUZHEthefool YUZHEthefool commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

两个issue的问题都在于关联类型 bound 递归 lowering 时,clause binder 只记录最内层 lifetime,引用的外层 lifetime 以 ^1/^2 形式逃逸。因此我修复了lower.rs中将 overarching 和内层 HRTB 变量合并到同一个 predicate binder,同时保留dyn Trait了作为真正独立的existential binder。

<The problem is that when the associated type bound is recursively lowering, the clause binder only records the innermost lifetime, and the outer lifetime of the reference escapes in the form of ^1/^2.
So I fix merging overarching and inner HRTB variables into the same predicate binder in lower.rs while retaining the dyn Trait's truly independent existential binder.>

In simpler terms: Outer lifetimes in nested binders are not flattened/renumbered correctly

Fix: #23063 and Fix #23064

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 14, 2026

@dfireBird dfireBird left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this. I have verified this with rustc and it seems rustc indeed flattens the trait predicate binders into one.

I'll let the implementation details for review with other team members.

View changes since this review

Comment thread crates/hir-ty/src/lower.rs Outdated
@YUZHEthefool
YUZHEthefool force-pushed the fix/nested-hrtb-predicate-binders branch from 8796ae2 to d0a84a4 Compare August 16, 2026 06:23
@YUZHEthefool

Copy link
Copy Markdown
Contributor Author

Now, lifetime search is changed to preferentially match the last name added in the same binder, correctly handle nested lifetime shadowing, and remove the previously incorrect index offset.
And I Improved testing

Comment thread crates/hir-ty/src/tests/regression/new_solver.rs Outdated
Comment thread crates/hir-ty/src/tests/regression/new_solver.rs Outdated
Comment thread crates/hir-ty/src/lower.rs Outdated
if let LifetimeRef::Named(lt_name) = &self.store[lifetime] {
self.bound_vars.iter().rev().enumerate().find_map(|(debruijn, (binder, _))| {
binder.iter().enumerate().find_map(|(index, l)| {
binder.iter().enumerate().rev().find_map(|(index, l)| {

@ChayimFriedman2 ChayimFriedman2 Aug 27, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread crates/hir-ty/src/lower.rs Outdated
@YUZHEthefool
YUZHEthefool force-pushed the fix/nested-hrtb-predicate-binders branch from d0a84a4 to 62b2fa4 Compare August 28, 2026 12:55
@rustbot

This comment has been minimized.

@YUZHEthefool
YUZHEthefool force-pushed the fix/nested-hrtb-predicate-binders branch from 62b2fa4 to 98e4292 Compare August 28, 2026 13:07
@rustbot

rustbot commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different master 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.

@ChayimFriedman2 ChayimFriedman2 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems more complicated than it needs to be. What is the problem with my suggestion (calling the callback with a new frame, and flattening only after it)?

View changes since this review

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

Projects

None yet

4 participants