Skip to content

trait solver: Handle reflexive region constraints - #161988

Open
Dnreikronos wants to merge 4 commits into
rust-lang:mainfrom
Dnreikronos:trait_solver/reflexive_region_constraints
Open

trait solver: Handle reflexive region constraints#161988
Dnreikronos wants to merge 4 commits into
rust-lang:mainfrom
Dnreikronos:trait_solver/reflexive_region_constraints

Conversation

@Dnreikronos

@Dnreikronos Dnreikronos commented Aug 29, 2026

Copy link
Copy Markdown
Contributor

Fixes rust-lang/project-assumptions-on-binders#19

A reflexive placeholder constraint like 'a: 'a can show up after we compute transitive region constraints. We then try to pull it out of the current universe by looking for lower-universe candidates. With none to choose from it becomes false, even though 'a: 'a was true the whole time.

I first had this buried in the binder region work, which made a green test pretty meaningless because too much else was changing around it. Split out on its own, the fix is just to accept equal regions before doing the universe rewrite. I think that is the sensible place to stop: it handles the direct case and the reflexive edges made by the transitive pass. I added a regression for the direct case.

cc/ @BoxyUwU o/

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 29, 2026
@rustbot

rustbot commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

r? @JohnTitor

rustbot has assigned @JohnTitor.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 75 candidates
  • Random selection from 21 candidates

@Dnreikronos
Dnreikronos marked this pull request as draft August 29, 2026 20:12
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 29, 2026
@rustbot rustbot added the WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) label Aug 30, 2026
@Dnreikronos

Dnreikronos commented Aug 30, 2026

Copy link
Copy Markdown
Contributor Author

Sup @BoxyUwU and @adwinwhite o/
I noticed #161963 has the same reflexive check as the first commit in this PR, so that part overlaps. I pushed a few more changes here because I don't think that check covers the whole problem in rust-lang/project-assumptions-on-binders#19.

The first check handles 'a: 'a while we're leaving the placeholder's universe. That check is still right, it just fires too early for the other case I was looking at. In the small syn repro, the type outlives constraint only gets taken apart once we're back at the root, so the earlier check never sees the reflexive region constraint.

When I followed that path, some information was missing from the assumptions used at the root. The implied I: '_ from &'_ self was in region_bound_pairs, but it wasn't included when we destructured the solver constraints. An assumption such as &'b u8: 'a also didn't always give this code the 'b: 'a relation.

There's a similar problem while leaving a binder. If the binder's own assumptions already prove 'b: 'a, we still try to rewrite it into a lower universe. When there are no lower-universe candidates, that turns a true constraint into Or([]). The new code checks whether the assumptions already prove it before doing that rewrite.

At the root, a RegionOutlives('a, 'a) produced by destructuring is now treated as true too. That's the part that gets the syn minimization through.

I added tests for direct and transitive assumptions, type outlives assumptions, and the root case. The full assumptions_on_binders UI directory passes locally, 17 tests, and tidy passes too. I haven't tested every affected case listed in #19 yet, so I don't want to claim more than I've checked.

My take is that #161963 is a good small fix for #161733, while this PR now deals with the wider path behind #19. I would keep the extra work here, but I'm not sure where you want the PR boundary. Would you rather keep it this way or move the extra changes to a follow-up on #161963?

@BoxyUwU BoxyUwU assigned BoxyUwU and unassigned JohnTitor Aug 30, 2026
@Dnreikronos
Dnreikronos marked this pull request as ready for review August 31, 2026 22:40
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 31, 2026
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. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

we dont handle 'a: 'a eagerly in some cases (?)

4 participants