diff options
| author | bors <bors@rust-lang.org> | 2025-08-23 20:16:58 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2025-08-23 20:16:58 +0000 |
| commit | 69b76df90c7ea63b5350d1865f92902a0b27c9a2 (patch) | |
| tree | 94d1ca31b26b42df8398c74d36bb3fa3e0c3c6ae /compiler/rustc_hir_analysis/src | |
| parent | c5a6a7bdd89f099544fa0d3fad4d833d238377ad (diff) | |
| parent | 17ac2fc96d7dc93b5a02b8f2fe5f03edade6f739 (diff) | |
| download | rust-69b76df90c7ea63b5350d1865f92902a0b27c9a2.tar.gz rust-69b76df90c7ea63b5350d1865f92902a0b27c9a2.zip | |
Auto merge of #145706 - lcnr:uniquification, r=BoxyUwU
change HIR typeck region uniquification handling approach rust-lang/rust#144405 causes structural lookup of opaque types to not work during HIR typeck, so instead avoid uniquifying goals and instead only reprove them if MIR borrowck actually encounters an error. This doesn't perfectly maintain the property that HIR typeck succeeding implies that MIR typeck succeeds, instead weakening this check to only guarantee that HIR typeck implies that MIR typeck succeeds modulo region uniquification. This means we still get the actually desirable ICEs if we MIR building is broken or we forget to check some property in HIR typeck, without having to deal with the fallout of uniquification in HIR typeck itself. We report errors using the original obligation sources of HIR typeck so diagnostics aren't that negatively impacted either. Here's the history of region uniquification while working on the new trait solver: - rust-lang/rust#107981 - rust-lang/rust#110180 - rust-lang/rust#114117 - rust-lang/rust#130821 - rust-lang/rust#144405 - rust-lang/rust#145706 <- we're here :tada: r? `@BoxyUwU`
Diffstat (limited to 'compiler/rustc_hir_analysis/src')
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/check.rs | 26 | ||||
| -rw-r--r-- | compiler/rustc_hir_analysis/src/check/mod.rs | 1 |
2 files changed, 27 insertions, 0 deletions
diff --git a/compiler/rustc_hir_analysis/src/check/check.rs b/compiler/rustc_hir_analysis/src/check/check.rs index 161a8566b04..eccb88a938f 100644 --- a/compiler/rustc_hir_analysis/src/check/check.rs +++ b/compiler/rustc_hir_analysis/src/check/check.rs @@ -2053,3 +2053,29 @@ pub(super) fn check_coroutine_obligations( Ok(()) } + +pub(super) fn check_potentially_region_dependent_goals<'tcx>( + tcx: TyCtxt<'tcx>, + def_id: LocalDefId, +) -> Result<(), ErrorGuaranteed> { + if !tcx.next_trait_solver_globally() { + return Ok(()); + } + let typeck_results = tcx.typeck(def_id); + let param_env = tcx.param_env(def_id); + + // We use `TypingMode::Borrowck` as we want to use the opaque types computed by HIR typeck. + let typing_mode = TypingMode::borrowck(tcx, def_id); + let infcx = tcx.infer_ctxt().ignoring_regions().build(typing_mode); + let ocx = ObligationCtxt::new_with_diagnostics(&infcx); + for (predicate, cause) in &typeck_results.potentially_region_dependent_goals { + let predicate = fold_regions(tcx, *predicate, |_, _| { + infcx.next_region_var(RegionVariableOrigin::Misc(cause.span)) + }); + ocx.register_obligation(Obligation::new(tcx, cause.clone(), param_env, predicate)); + } + + let errors = ocx.select_all_or_error(); + debug!(?errors); + if errors.is_empty() { Ok(()) } else { Err(infcx.err_ctxt().report_fulfillment_errors(errors)) } +} diff --git a/compiler/rustc_hir_analysis/src/check/mod.rs b/compiler/rustc_hir_analysis/src/check/mod.rs index 85445cb3c00..2e4b151d4dc 100644 --- a/compiler/rustc_hir_analysis/src/check/mod.rs +++ b/compiler/rustc_hir_analysis/src/check/mod.rs @@ -109,6 +109,7 @@ pub(super) fn provide(providers: &mut Providers) { collect_return_position_impl_trait_in_trait_tys, compare_impl_item: compare_impl_item::compare_impl_item, check_coroutine_obligations: check::check_coroutine_obligations, + check_potentially_region_dependent_goals: check::check_potentially_region_dependent_goals, check_type_wf: wfcheck::check_type_wf, check_well_formed: wfcheck::check_well_formed, ..*providers |
