move implied bounds computation out of borrowck - #160491
Open
lcnr wants to merge 4 commits into
Open
Conversation
Contributor
Author
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 4, 2026
move implied bounds computation out of borrowck
This was referenced Aug 4, 2026
lcnr
force-pushed
the
implied-bounds-opaque
branch
5 times, most recently
from
August 4, 2026 10:01
6eb8247 to
1dd6c27
Compare
Contributor
Author
|
@bors cancel @bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
Contributor
|
❗ There is currently no auto build in progress on this PR. Hint: There is a pending try build on this PR. Maybe you meant to cancel it? You can do that using |
This comment has been minimized.
This comment has been minimized.
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 4, 2026
move implied bounds computation out of borrowck
Contributor
Author
|
@bors try @rust-timer queue |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
rust-bors Bot
pushed a commit
that referenced
this pull request
Aug 4, 2026
move implied bounds computation out of borrowck
lcnr
marked this pull request as ready for review
August 4, 2026 12:17
Collaborator
|
r? @JohnTitor rustbot has assigned @JohnTitor. Use Why was this reviewer chosen?The reviewer was selected based on:
|
lcnr
force-pushed
the
implied-bounds-opaque
branch
from
August 6, 2026 11:29
9151a02 to
73c2b60
Compare
This comment has been minimized.
This comment has been minimized.
lcnr
force-pushed
the
implied-bounds-opaque
branch
from
August 6, 2026 12:20
73c2b60 to
4dd4689
Compare
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 6, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 6, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 7, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 7, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
adwinwhite
reviewed
Aug 7, 2026
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 7, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 7, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
jhpratt
added a commit
to jhpratt/rust
that referenced
this pull request
Aug 7, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Aug 7, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang#160491 is otherwise a mess. r? types
This comment has been minimized.
This comment has been minimized.
rust-timer
added a commit
that referenced
this pull request
Aug 8, 2026
Rollup merge of #160504 - lcnr:borrowck-cleanup, r=oli-obk cleanup borrowck, improve c-variadic handling The first commits of #160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for #160491 is otherwise a mess. r? types
pull Bot
pushed a commit
to LeeeeeeM/miri
that referenced
this pull request
Aug 8, 2026
cleanup borrowck, improve c-variadic handling The first commits of rust-lang/rust#160491. Hopefully all of them make sense. It feels intuitive to me that the `c-variadic` region should be just another late-bound region and tracking region correctly for rust-lang/rust#160491 is otherwise a mess. r? types
lcnr
force-pushed
the
implied-bounds-opaque
branch
from
August 10, 2026 08:19
4dd4689 to
1d41843
Compare
Collaborator
|
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 comment has been minimized.
This comment has been minimized.
lcnr
force-pushed
the
implied-bounds-opaque
branch
from
August 10, 2026 12:09
e944e8c to
28e8abd
Compare
This comment has been minimized.
This comment has been minimized.
lcnr
force-pushed
the
implied-bounds-opaque
branch
from
August 10, 2026 15:18
28e8abd to
d4ad7a6
Compare
adwinwhite
reviewed
Aug 11, 2026
lcnr
force-pushed
the
implied-bounds-opaque
branch
from
August 11, 2026 08:51
d4ad7a6 to
6898626
Compare
This comment has been minimized.
This comment has been minimized.
lcnr
force-pushed
the
implied-bounds-opaque
branch
from
August 11, 2026 08:58
6898626 to
760b9ae
Compare
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.
View all comments
@tiif did the initial implementation work in #152051. This ended up being more involved than I originally expected, so I ended up finishing this PR after spending a few days on it myself.
Computing implied bounds now happens in a new query
mir_borrowck_implied_outlives_boundswhich does two things differently from MIR borrowck:Using param and placeholder regions instead of NLL vars
This fixes #106569. We previously computed the implied bounds using
ty::ReVareven for universal variables, which meant that resolving them can drop constraints in borrowck.As explained in #106569 (comment)
Computing implied bounds now uses universal variables instead of
ReVar, fixing this issue.Do not reveal the hidden type of opaques for typeck roots
This fixes rust-lang/trait-system-refactor-initiative#159 with the new trait solver.
Computing the implied bounds for
boompreviously revealed the hidden type ofimpl Extend<'a, 'b>giving us a'a: 'bimplied bound. Callingboomcannot reveal the opaque type as it's outside of the defining scope, so the caller never has to prove that outlives requirement.We do still reveal opaque types when computing the implied bounds for nested bodies! This is subtle and I nearly missed this. For nested bodies, they are only ever used inside of their parent function, which is able to define the same opaque types. We never check that e.g. a closure is well-formed outside of the parent body.
This means trying to compute implied bounds for closures without defining opaque types can result in incorrect errors, see tests/ui/traits/next-solver/opaques/implied-bounds-opaque-hidden-in-closure-sig.rs:
Implementation details and nuances
var_valuesReturning implied bounds and canonicalization. Figuring out how to do so was quite challenging. The main question is how to link regions from the query to the correct regions in MIR borrowck. The way to do so is via
var_values.As we're using old style canonicalizing we keep early and late bound parameters around, so these don't have to be part of the
var_values. We do need to link regions from the closure signature in the query to the regions in the signature used in MIR borrowck. We do this by going over the signature and collecting all regions we find in thevar_values. The query uses placeholders for these while MIR borrowck uses external NLL vars for them.Normalizing the signature and unconstrained region vars
Normalizing a function signature can result in unconstrained existential regions due to #136547. Types involving these regions can be relevant for implied bounds. Using such type outlives bounds relies on structural equality. If we separately normalize the signature two times, once in borrowck and once in the implied bounds query, we get different unconstrained region vars, breaking the
gluon_salsatest.To avoid this,
mir_borrowck_implied_outlives_boundsnormalizes the signature without revealing opaque types and returns its result to MIR borrowck. MIR borrowck now renormalizes this signature to also correctly normalize opaque types.The bevy implied bounds hack
This PR keeps the current behavior of #119956 while somewhat changing the actual implementation.
We continue to consider constraints from computing implied bounds as implied bounds only for arguments whose type mentions
bevy_ecs::ParamSet.