Skip to content

Commit c104ee9

Browse files
Move check_region_obligations_and_report_errors to TypeErrCtxt
1 parent c757267 commit c104ee9

File tree

7 files changed

+34
-31
lines changed

7 files changed

+34
-31
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ fn check_opaque_meets_bounds<'tcx>(
468468
// Can have different predicates to their defining use
469469
hir::OpaqueTyOrigin::TyAlias => {
470470
let outlives_environment = OutlivesEnvironment::new(param_env);
471-
let _ = infcx.check_region_obligations_and_report_errors(
471+
let _ = infcx.err_ctxt().check_region_obligations_and_report_errors(
472472
defining_use_anchor,
473473
&outlives_environment,
474474
);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -619,7 +619,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
619619
Some(infcx),
620620
infcx.implied_bounds_tys(param_env, impl_m_hir_id, wf_tys),
621621
);
622-
infcx.check_region_obligations_and_report_errors(
622+
infcx.err_ctxt().check_region_obligations_and_report_errors(
623623
impl_m.def_id.expect_local(),
624624
&outlives_environment,
625625
)?;
@@ -1651,8 +1651,9 @@ pub(super) fn compare_impl_const_raw(
16511651
}
16521652

16531653
let outlives_environment = OutlivesEnvironment::new(param_env);
1654-
infcx.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment)?;
1655-
1654+
infcx
1655+
.err_ctxt()
1656+
.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment)?;
16561657
Ok(())
16571658
}
16581659

@@ -1760,7 +1761,7 @@ fn compare_type_predicate_entailment<'tcx>(
17601761
// Finally, resolve all regions. This catches wily misuses of
17611762
// lifetime parameters.
17621763
let outlives_environment = OutlivesEnvironment::new(param_env);
1763-
infcx.check_region_obligations_and_report_errors(
1764+
infcx.err_ctxt().check_region_obligations_and_report_errors(
17641765
impl_ty.def_id.expect_local(),
17651766
&outlives_environment,
17661767
)?;
@@ -1974,7 +1975,7 @@ pub(super) fn check_type_bounds<'tcx>(
19741975
let outlives_environment =
19751976
OutlivesEnvironment::with_bounds(param_env, Some(&infcx), implied_bounds);
19761977

1977-
infcx.check_region_obligations_and_report_errors(
1978+
infcx.err_ctxt().check_region_obligations_and_report_errors(
19781979
impl_ty.def_id.expect_local(),
19791980
&outlives_environment,
19801981
)?;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ pub(super) fn enter_wf_checking_ctxt<'tcx, F>(
115115
let outlives_environment =
116116
OutlivesEnvironment::with_bounds(param_env, Some(infcx), implied_bounds);
117117

118-
let _ = infcx.check_region_obligations_and_report_errors(body_def_id, &outlives_environment);
118+
let _ = infcx
119+
.err_ctxt()
120+
.check_region_obligations_and_report_errors(body_def_id, &outlives_environment);
119121
}
120122

121123
fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) {

compiler/rustc_hir_analysis/src/coherence/builtin.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,9 @@ fn visit_implementation_of_dispatch_from_dyn(tcx: TyCtxt<'_>, impl_did: LocalDef
325325

326326
// Finally, resolve all regions.
327327
let outlives_env = OutlivesEnvironment::new(param_env);
328-
let _ = infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
328+
let _ = infcx
329+
.err_ctxt()
330+
.check_region_obligations_and_report_errors(impl_did, &outlives_env);
329331
}
330332
}
331333
_ => {
@@ -565,7 +567,7 @@ pub fn coerce_unsized_info<'tcx>(tcx: TyCtxt<'tcx>, impl_did: DefId) -> CoerceUn
565567

566568
// Finally, resolve all regions.
567569
let outlives_env = OutlivesEnvironment::new(param_env);
568-
let _ = infcx.check_region_obligations_and_report_errors(impl_did, &outlives_env);
570+
let _ = infcx.err_ctxt().check_region_obligations_and_report_errors(impl_did, &outlives_env);
569571

570572
CoerceUnsizedInfo { custom_kind: kind }
571573
}

compiler/rustc_hir_analysis/src/impl_wf_check/min_specialization.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ fn get_impl_substs(
181181

182182
let implied_bounds = infcx.implied_bounds_tys(param_env, impl1_hir_id, assumed_wf_types);
183183
let outlives_env = OutlivesEnvironment::with_bounds(param_env, Some(infcx), implied_bounds);
184-
let _ = infcx.check_region_obligations_and_report_errors(impl1_def_id, &outlives_env);
184+
let _ =
185+
infcx.err_ctxt().check_region_obligations_and_report_errors(impl1_def_id, &outlives_env);
185186
let Ok(impl2_substs) = infcx.fully_resolve(impl2_substs) else {
186187
let span = tcx.def_span(impl1_def_id);
187188
tcx.sess.emit_err(SubstsOnOverriddenImpl { span });

compiler/rustc_infer/src/infer/mod.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -1681,13 +1681,29 @@ impl<'tcx> InferCtxt<'tcx> {
16811681
}
16821682

16831683
impl<'tcx> TypeErrCtxt<'_, 'tcx> {
1684+
/// Processes registered region obliations and resolves regions, reporting
1685+
/// any errors if any were raised. Prefer using this function over manually
1686+
/// calling `resolve_regions_and_report_errors`.
1687+
pub fn check_region_obligations_and_report_errors(
1688+
&self,
1689+
generic_param_scope: LocalDefId,
1690+
outlives_env: &OutlivesEnvironment<'tcx>,
1691+
) -> Result<(), ErrorGuaranteed> {
1692+
self.process_registered_region_obligations(
1693+
outlives_env.region_bound_pairs(),
1694+
outlives_env.param_env,
1695+
);
1696+
1697+
self.resolve_regions_and_report_errors(generic_param_scope, outlives_env)
1698+
}
1699+
16841700
/// Process the region constraints and report any errors that
16851701
/// result. After this, no more unification operations should be
16861702
/// done -- or the compiler will panic -- but it is legal to use
16871703
/// `resolve_vars_if_possible` as well as `fully_resolve`.
16881704
///
16891705
/// Make sure to call [`InferCtxt::process_registered_region_obligations`]
1690-
/// first, or preferably use [`InferCtxt::check_region_obligations_and_report_errors`]
1706+
/// first, or preferably use [`TypeErrCtxt::check_region_obligations_and_report_errors`]
16911707
/// to do both of these operations together.
16921708
pub fn resolve_regions_and_report_errors(
16931709
&self,

compiler/rustc_infer/src/infer/outlives/obligations.rs

+1-20
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,14 @@
6060
//! imply that `'b: 'a`.
6161
6262
use crate::infer::outlives::components::{push_outlives_components, Component};
63-
use crate::infer::outlives::env::OutlivesEnvironment;
6463
use crate::infer::outlives::env::RegionBoundPairs;
6564
use crate::infer::outlives::verify::VerifyBoundCx;
6665
use crate::infer::{
6766
self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, UndoLog, VerifyBound,
6867
};
6968
use crate::traits::{ObligationCause, ObligationCauseCode};
7069
use rustc_data_structures::undo_log::UndoLogs;
71-
use rustc_errors::ErrorGuaranteed;
7270
use rustc_hir::def_id::DefId;
73-
use rustc_hir::def_id::LocalDefId;
7471
use rustc_middle::mir::ConstraintCategory;
7572
use rustc_middle::ty::subst::GenericArgKind;
7673
use rustc_middle::ty::{self, Region, SubstsRef, Ty, TyCtxt, TypeVisitable};
@@ -116,7 +113,7 @@ impl<'tcx> InferCtxt<'tcx> {
116113
std::mem::take(&mut self.inner.borrow_mut().region_obligations)
117114
}
118115

119-
/// NOTE: Prefer using [`InferCtxt::check_region_obligations_and_report_errors`]
116+
/// NOTE: Prefer using `TypeErrCtxt::check_region_obligations_and_report_errors`
120117
/// instead of calling this directly.
121118
///
122119
/// Process the region obligations that must be proven (during
@@ -170,22 +167,6 @@ impl<'tcx> InferCtxt<'tcx> {
170167
outlives.type_must_outlive(origin, sup_type, sub_region, category);
171168
}
172169
}
173-
174-
/// Processes registered region obliations and resolves regions, reporting
175-
/// any errors if any were raised. Prefer using this function over manually
176-
/// calling `resolve_regions_and_report_errors`.
177-
pub fn check_region_obligations_and_report_errors(
178-
&self,
179-
generic_param_scope: LocalDefId,
180-
outlives_env: &OutlivesEnvironment<'tcx>,
181-
) -> Result<(), ErrorGuaranteed> {
182-
self.process_registered_region_obligations(
183-
outlives_env.region_bound_pairs(),
184-
outlives_env.param_env,
185-
);
186-
187-
self.err_ctxt().resolve_regions_and_report_errors(generic_param_scope, outlives_env)
188-
}
189170
}
190171

191172
/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`

0 commit comments

Comments
 (0)