rust/compiler
bors 75ee9ffd5e Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU
`-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. 564ee21912/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-01 20:56:46 +00:00
..
rustc rename stable_mir to rustc_public, and rustc_smir to rustc_public_bridge 2025-07-14 09:25:54 +00:00
rustc_abi Rollup merge of #144443 - WaffleLapkin:integer-target-pointer-width, r=Noratrieb 2025-08-31 13:40:34 +02:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast Rollup merge of #145984 - nnethercote:TokenStream-cleanups, r=chenyukang 2025-08-29 12:37:32 +02:00
rustc_ast_ir turn pointer width into an integer in target.json 2025-08-27 23:44:49 +02:00
rustc_ast_lowering Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_ast_passes Add new doc(attribute = "...") attribute 2025-08-28 15:56:29 +02:00
rustc_ast_pretty Add itertools to [workspace.dependencies]. 2025-08-27 14:21:21 +10:00
rustc_attr_parsing Remove incorrect FIXME 2025-08-30 13:44:13 +02:00
rustc_baked_icu_data Use default locale fallback data 2025-08-28 09:48:54 +00:00
rustc_borrowck Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU 2025-09-01 20:56:46 +00:00
rustc_builtin_macros Rollup merge of #145905 - TaKO8Ki:fix-137580, r=nnethercote 2025-08-27 11:26:52 +02:00
rustc_codegen_cranelift Introduce MirDumper and MirWriter. 2025-09-01 09:19:03 +10:00
rustc_codegen_gcc fix target-pointer-width in tests 2025-08-27 23:44:49 +02:00
rustc_codegen_llvm Auto merge of #145721 - dpaoliello:ar050, r=bjorn3 2025-09-01 17:50:01 +00:00
rustc_codegen_ssa Move to 0.50.1 2025-08-29 16:39:16 -07:00
rustc_const_eval Add rustc_apfloat to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
rustc_data_structures Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU 2025-09-01 20:56:46 +00:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Add serde_json to [workspace.dependencies]. 2025-08-28 20:10:54 +10:00
rustc_error_codes Changes to the uitests 2025-08-27 20:25:18 +02:00
rustc_error_messages Use default locale fallback data 2025-08-28 09:48:54 +00:00
rustc_errors Rollup merge of #145947 - nnethercote:workspace-members-2, r=Kobzol 2025-08-29 12:54:12 +10:00
rustc_expand Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_feature Add serde_json to [workspace.dependencies]. 2025-08-28 20:10:54 +10:00
rustc_fluent_macro Add proc-macro2 and quote to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
rustc_fs_util Add tempfile to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
rustc_graphviz Remove #![warn(unreachable_pub)] from all compiler/ crates. 2025-03-11 13:14:21 +11:00
rustc_hashes Revert "Use workspace lints for crates in compiler/ #138084" 2025-03-10 18:12:47 +08:00
rustc_hir Rollup merge of #145947 - nnethercote:workspace-members-2, r=Kobzol 2025-08-29 12:54:12 +10:00
rustc_hir_analysis autoderef final ty is already resolved 2025-08-29 10:53:39 +02:00
rustc_hir_id rustc_hir_id: Add a comment explaining why the crate exists 2025-08-20 15:04:00 -07:00
rustc_hir_pretty Propagate TraitImplHeader to hir 2025-08-11 17:05:42 -05:00
rustc_hir_typeck Rollup merge of #146046 - chenyukang:yukang-fix-method-exists-for-ret-ty-error, r=estebank 2025-09-01 12:42:27 +10:00
rustc_incremental Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_index Update documentation. 2025-08-24 22:15:19 +00:00
rustc_index_macros Add proc-macro2 and quote to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
rustc_infer Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU 2025-09-01 20:56:46 +00:00
rustc_interface Move NativeLibKind from rustc_session to rustc_hir 2025-08-27 20:24:59 +02:00
rustc_lexer fix(lexer): Don't require frontmatters to be escaped with indented fences 2025-08-28 14:08:33 -05:00
rustc_lint Rollup merge of #145941 - Urgau:int_to_ptr_transmutes-unsized, r=lcnr 2025-08-28 23:10:37 +10:00
rustc_lint_defs Fix stage 1 compiler tests 2025-08-30 15:28:41 +02:00
rustc_llvm Update to ar_archive_writer 0.5.1 2025-08-29 16:37:42 -07:00
rustc_log Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_macros Add proc-macro2 and quote to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
rustc_metadata Rollup merge of #145947 - nnethercote:workspace-members-2, r=Kobzol 2025-08-29 12:54:12 +10:00
rustc_middle Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU 2025-09-01 20:56:46 +00:00
rustc_mir_build Auto merge of #144783 - folkertdev:loop-match-diverging-loop, r=SparrowLii 2025-09-01 14:42:07 +00:00
rustc_mir_dataflow Introduce MirDumper and MirWriter. 2025-09-01 09:19:03 +10:00
rustc_mir_transform Auto merge of #146077 - Zalathar:rollup-l7ip5yi, r=Zalathar 2025-09-01 07:44:42 +00:00
rustc_monomorphize Auto merge of #143290 - azhogin:azhogin/link-pub-async-impls, r=oli-obk 2025-09-01 10:54:40 +00:00
rustc_next_trait_solver Auto merge of #145978 - Zalathar:rollup-0dzk72g, r=Zalathar 2025-08-29 03:40:14 +00:00
rustc_parse Auto merge of #145582 - estebank:issue-107806, r=chenyukang 2025-08-31 03:00:54 +00:00
rustc_parse_format Rollup merge of #145592 - nilotpal-n7:fix-format-alignment, r=lcnr 2025-08-31 13:40:35 +02:00
rustc_passes Rollup merge of #142472 - GuillaumeGomez:doc-attribute-attribute, r=fmease 2025-08-28 21:41:00 +02:00
rustc_pattern_analysis Add rustc-hash to [workspace.dependencies]. 2025-08-28 20:11:43 +10:00
rustc_privacy Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_proc_macro Add rustc-literal-escaper to [workspace.dependencies]. 2025-08-27 13:59:32 +10:00
rustc_public Add scoped-tls to [workspace.dependencies]. 2025-08-28 20:12:16 +10:00
rustc_public_bridge Remove useless lifetime parameter. 2025-07-23 23:54:37 +00:00
rustc_query_impl Add measureme to [workspace.dependencies]. 2025-08-28 20:12:14 +10:00
rustc_query_system Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_resolve resolve: Merge ExternPreludeEntry::only_item into flag_binding 2025-08-29 18:42:04 +03:00
rustc_sanitizers Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_serialize Add indexmap to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00
rustc_session Rollup merge of #145947 - nnethercote:workspace-members-2, r=Kobzol 2025-08-29 12:54:12 +10:00
rustc_span Rollup merge of #145756 - okaneco:stabilize_char_boundary, r=scottmcm 2025-08-29 19:33:03 -05:00
rustc_symbol_mangling Add rustc-demangle to [workspace.dependencies]. 2025-08-28 20:12:16 +10:00
rustc_target Rollup merge of #144443 - WaffleLapkin:integer-target-pointer-width, r=Noratrieb 2025-08-31 13:40:34 +02:00
rustc_thread_pool Add scoped-tls to [workspace.dependencies]. 2025-08-28 20:12:16 +10:00
rustc_trait_selection Split ObligationCauseCode::BinOp for unops to UnOp 2025-08-31 21:13:12 +00:00
rustc_traits Add tracing to [workspace.dependencies]. 2025-08-27 14:21:19 +10:00
rustc_transmute Add itertools to [workspace.dependencies]. 2025-08-27 14:21:21 +10:00
rustc_ty_utils Auto merge of #145925 - lcnr:revealing-use-closures-2, r=BoxyUwU 2025-09-01 20:56:46 +00:00
rustc_type_ir Auto merge of #145978 - Zalathar:rollup-0dzk72g, r=Zalathar 2025-08-29 03:40:14 +00:00
rustc_type_ir_macros Add proc-macro2 and quote to [workspace.dependencies]. 2025-08-28 20:10:55 +10:00