about summary refs log tree commit diff
path: root/compiler/rustc_borrowck/src/region_infer
AgeCommit message (Collapse)AuthorLines
2025-09-29more renameBoxy Uwu-12/+17
2025-09-27Rename various "concrete opaque type" terminology to say "hidden type"Boxy Uwu-53/+30
2025-09-24Rollup merge of #146711 - lcnr:fix-placeholder-ice, r=lqdMatthias Krüger-3/+4
fix 2 borrowck issues fixes https://github.com/rust-lang/rust/issues/146467 cc ``@amandasystems`` our understanding here is as follows: region constraints from computing implied bounds gets `ConstraintCategory::Internal`. If there's a higher-ranked subtyping errors while computing implied bounds we then ended up with only `ConstraintCategory::Internal` and `ConstraintCategory::OutlivesUnnameablePlaceholder(_)` constraints. The path was something like - `'placeholderU2: 'placeholderU1` (`Internal`) - `'placeholderU1: 'static` (`OutlivesUnnameablePlaceholder('placeholderU2)`) It's generally somewhat subtle here as ideally relating placeholders doesn't introduce `'static` constraints. Relating the placeholders themselves will always error regardless, cc https://github.com/rust-lang/rust/pull/142623. --- separately fixes https://github.com/rust-lang/rust/pull/145925#issuecomment-3303733357 by updating the location for deferred closure requirements inside of promoteds. I am not updating their category as doing so is 1) effort and 2) imo actually undesirable :thinking: see the comments in `TypeChecker::check_promoted` cc ``@lqd`` r? lqd
2025-09-18Clean up universe evaluation during type test evaluationAmanda Stjerna-5/+15
The logic was, as the removed comments suggest, hackish and meant to implement previous logic that was factored out. The new logic does exactly what the comments say, and is much less surprising.
2025-09-18internal constraints are better than placeholder outliveslcnr-3/+4
2025-09-09erase_regions to erase_and_anonymize_regionsBoxy-2/+2
2025-09-06identity uses are ok, even if there are no defining useslcnr-1/+10
2025-09-01Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwUbors-76/+88
`-Znext-solver`: support non-defining uses in closures Cleaned up version of rust-lang/rust#139587, finishing the implementation of https://github.com/rust-lang/types-team/issues/129. This does not affect stable. The reasoning for why this is the case is subtle however. ## What does it do We split `do_mir_borrowck` into `borrowck_collect_region_constraints` and `borrowck_check_region_constraints`, where `borrowck_collect_region_constraints` returns an enormous `CollectRegionConstraintsResult` struct which contains all the relevant data to actually handle opaque type uses and to check the region constraints later on. `query mir_borrowck` now simply calls `BorrowCheckRootCtxt::do_mir_borrowck` which starts by iterating over all nested bodies of the current function - visiting nested bodies before their parents - and computing their `CollectRegionConstraintsResult`. After we've collected all constraints it's time to actually compute the concrete types for the opaques defined by this function. With this PR we now compute the concrete types of opaques for each body before using them to check the non-defining uses of any of them. After we've computed the concrete types by using all bodies, we use `apply_computed_concrete_opaque_types` for each body to constrain non-defining uses, before finally finishing with `borrowck_check_region_constraints`. We always visit nested bodies before their parents when doing this. ## `ClosureRegionRequirements` As we only call `borrowck_collect_region_constraints` for nested bodies before type checking the parent, we can't simply use the final `ClosureRegionRequirements` of the nested body during MIR type check. We instead track that we need to apply these requirements in `deferred_closure_requirements`. We now manually apply the final closure requirements to each body after handling opaque types. This works, except that we may need the region constraints of nested bodies to successfully define an opaque type in the parent. This is handled by using a new `fn compute_closure_requirements_modulo_opaques` which duplicates region checking - while ignoring any errors - before we've added the constraints from `apply_computed_concrete_opaque_types`. This is necessary for a lot of async tests, as pretty much the entire function is inside of an async block while the opaque type gets defined in the parent. As an performance optimization we only use `fn compute_closure_requirements_modulo_opaques` in case the nested body actually depends on any opaque types. Otherwise we eagerly call `borrowck_check_region_constraints` and apply the final closure region requirements right away. ## Impact on stable code Handling the opaque type uses in the parent function now only uses the closure requirements *modulo opaques*, while it previously also considered member constraints from nested bodies. `External` regions are never valid choice regions. Also, member constraints will never constrain a member region if it is required to be outlived by an external region, as that fails the upper-bound check. https://github.com/rust-lang/rust/blob/564ee219127b796d56f74767366fd359758b97de/compiler/rustc_borrowck/src/region_infer/opaque_types/member_constraints.rs#L90-L96 Member constraints therefore never add constraints for external regions :> r? `@BoxyUwU`
2025-09-01use defining uses of all bodies to constrain non-defining useslcnr-76/+88
support non-defining uses in closures
2025-08-27Auto merge of #140737 - amandasystems:revised-constraint-search, r=lcnrbors-125/+84
Region inference: Use outlives-static constraints in constraint search Revise the extra `r: 'static` constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive `'static`. This cosmetically changes the output of two UI tests. I blessed them i separate commits with separate motivations, but that can of course be squashed as desired. We probably want that. The PR was extracted out of rust-lang/rust#130227 and consists of one-third of its functional payload. r? lcnr
2025-08-25change non-defining use error messagelcnr-1/+0
2025-08-25support non-defining uses in HIR typecklcnr-10/+10
2025-08-23Simplify SCC annotations somewhatAmanda Stjerna-13/+1
2025-08-22Region inference: Use outlives-static constraints in constraint searchAmanda Stjerna-112/+83
Revise the extra `r: 'static` constraints added upon universe issues to add an explanation, and use that explanation during constraint blame search. This greatly simplifies the region inference logic, which now does not need to reverse-engineer the event that caused a region to outlive 'static.
2025-08-20diagnostics :3lcnr-18/+42
2025-08-20handle opaque types before region inferencelcnr-446/+869
2025-08-20`region_infer::opaque_types` to folderlcnr-0/+0
2025-08-15Auto merge of #142071 - lcnr:revealing-use, r=compiler-errorsbors-1/+8
`apply_member_constraints`: fix placeholder check Checking whether the member region is *an existential region from a higher universe* is just wrong and I am pretty sure we've added that check by accident as the naming was just horribly confusing before rust-lang/rust#140466. I've encountered this issue separately while working on rust-lang/rust#139587, but feel like it's probably easier to separately FCP this change. This allows the following code to compile ```rust trait Proj<'a> { type Assoc; } impl<'a, 'b, F: FnOnce() -> &'b ()> Proj<'a> for F { type Assoc = (); } fn is_proj<F: for<'a> Proj<'a>>(f: F) {} fn define<'a>() -> impl Sized + use<'a> { // This adds a use of `opaque::<'a>` with hidden type `&'unconstrained_b ()`. // 'unconstrained_b is an inference variable from a higher universe as it gets // created inside of the binder of `F: for<'a> Proj<'a>`. This previously // caused us to not apply member constraints. We now do, constraining // it to `'a`. is_proj(define::<'a>); &() } fn main() {} ``` This should not be breaking change, even in theory. Applying member constraints is incomplete in rare circumstances which means that applying them in more cases can cause spurious errors, cc rust-lang/rust#140569/rust-lang/rust#142073. However, as we always skipped these member regions in `apply_member_constraints` the skipped region is guaranteed to cause an error in `check_member_constraints` later on.
2025-08-11remove `from_forall`lcnr-4/+9
2025-08-09Rollup merge of #145115 - lcnr:less-borrowck-tainting, r=compiler-errorsStuart Cook-36/+44
defer opaque type errors, generally greatly reduce tainting fixes the test for rust-lang/rust#135528, does not actually fix that issue properly. This is useful as it causes the migration to rust-lang/rust#139587 to be a lot easier.
2025-08-08borrowck: defer opaque type errorslcnr-36/+44
2025-08-08apply_member_constraints: fix placeholder checklcnr-1/+8
2025-08-06Track names of existentialsAmanda Stjerna-3/+4
2025-08-06Proposed formatAmanda Stjerna-3/+3
2025-08-06Add annotations to the graphviz region graph on region originsAmanda Stjerna-1/+15
This adds - (ex) for regions whose origin is existential, - (p) for regoins whose origin is a placeholder, and - (p for <name>) if the originating placeholder is named. This has helped _my_ debugging and it doesn't create too bad clutter, I feel. The change is ridiculously small, but I turned it into a separate PR so we can bikeshed the format.
2025-08-02Rollup merge of #144478 - joshtriplett:doc-code-formatting-prep, r=AmanieuSamuel Tardieu-1/+1
Improve formatting of doc code blocks We don't currently apply automatic formatting to doc comment code blocks. As a result, it has built up various idiosyncracies, which make such automatic formatting difficult. Some of those idiosyncracies also make things harder for human readers or other tools. This PR makes a few improvements to doc code formatting, in the hopes of making future automatic formatting easier, as well as in many cases providing net readability improvements. I would suggest reading each commit separately, as each commit contains one class of changes.
2025-07-28use let chains in ast, borrowck, codegen, const_evalKivooeo-36/+32
2025-07-25Skip formatting for some compiler documentation codeJosh Triplett-1/+1
These examples feature Rust code that's presented primarily to illustrate how its compilation would be handled, and these examples are formatted to highlight those aspects in ways that rustfmt wouldn't preserve. Turn formatting off in those examples. (Doc code isn't formatted yet, but this will make it easier to enable doc code formatting in the future.)
2025-07-04Remove Symbol for Named LateParam/Bound variantsMichael Goulet-9/+25
2025-06-05Auto merge of #140466 - amandasystems:move-to-preprocessing-step, r=lcnrbors-198/+56
Move placeholder handling to a proper preprocessing step This commit breaks out the logic of placheolder rewriting into its own preprocessing step. It's one of the more boring parts of #130227. The only functional change from this is that the preprocessing step (where extra `r: 'static` constraints are added) is performed upstream of Polonius legacy, finally affecting Polonius. That is mostly a by-product, though. This should be reviewable by anyone in the compiler team, so r? rust-lang/compiler
2025-06-04Use an enum for SCC representatives, plus other code reviewAmanda Stjerna-38/+56
Co-authored-by: lcnr <rust@lcnr.de>
2025-06-03Move placeholder handling to a proper preprocessing stepAmanda Stjerna-184/+24
This commit breaks out the logic of placheolder rewriting into its own preprocessing step. The only functional change from this is that the preprocessing step (where extra `r: 'static` constraints are added) is performed upstream of Polonius legacy, finally affecting Polonius. That is mostly a by-product, though.
2025-05-31Drive-by refactor: use `OnceCell` for the reverse region SCC graphAmanda Stjerna-18/+11
2025-05-03`fn check_opaque_type_parameter_valid` defer errorlcnr-2/+2
2025-05-03add `ReverseSccGraph::compute`lcnr-18/+27
2025-04-28Use associated types for SCC annotations, per code review suggestionAmanda Stjerna-13/+10
2025-04-28Decouple SCC annotations from SCCsAmanda Stjerna-10/+43
This rewires SCC annotations to have them be a separate, visitor-type data structure. It was broken out of #130227, which needed them to be able to remove unused annotations after computation without recomputing the SCCs themselves. As a drive-by it also removes some redundant code from the hot loop in SCC construction for a performance improvement.
2025-04-25Rollup merge of #140257 - amandasystems:housecleaning, r=wesleywiserMatthias Krüger-23/+20
Some drive-by housecleaning in `rustc_borrowck` This commit picks up a few odd ends discovered during the work on #130227. It adds some documentation and renames a few methods with too generic names to describe what they actually do. It also adds some debug output that was helpful during bug hunting and generally cleans up a few things (for my values of "clean"). r? lcnr
2025-04-24Some drive-by housecleaning in `rustc_borrowck`Amanda Stjerna-23/+20
This commit picks up a few odd ends discovered during the work on #130227. It adds some documentation and renames a few methods with too generic names to describe what they actually do. It also adds some debug output that was helpful during bug hunting.
2025-04-14Use `newtype_index!`-generated types more idiomaticallyYotam Ofek-2/+1
2025-04-11eagerly initialize `definitions` in sub-fnlcnr-20/+23
2025-04-08Auto merge of #139536 - matthiaskrgr:rollup-j6goald, r=matthiaskrgrbors-5/+2
Rollup of 7 pull requests Successful merges: - #139476 (rm `RegionInferenceContext::var_infos`) - #139485 (compiletest: Stricter parsing for diagnostic kinds) - #139491 (Update books) - #139500 (document panic behavior of Vec::resize and Vec::resize_with) - #139501 (Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types) - #139504 (add missing word in doc comment) - #139509 (clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()`) r? `@ghost` `@rustbot` modify labels: rollup
2025-04-08Rollup merge of #139509 - xizheyin:issue-139359, r=lcnrMatthias Krüger-1/+1
clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()` Closes #139359 r? `@lcnr`
2025-04-08Rollup merge of #139476 - lcnr:rm-var_infos, r=compiler-errorsMatthias Krüger-4/+1
rm `RegionInferenceContext::var_infos` we already track this info in the `definitions` field r? types
2025-04-08clean code: remove Deref<Target=RegionKind> impl for Region and use `.kind()`xizheyin-1/+1
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-08move `ClosureRegionRequirements` to `rustc_borrowck`lcnr-4/+6
2025-04-08borrowck typeck children together with their parentlcnr-6/+6
2025-04-07rm `RegionInferenceContext::var_infos`lcnr-4/+1
we already track this info in the `definitions` field
2025-04-07Trivial tweaks to stop tracking source span directlyMichael Goulet-14/+18
2025-04-03add `TypingMode::Borrowck`lcnr-5/+13