Skip to content

Commit 10529bc

Browse files
author
Yuki Okushi
authored
Rollup merge of rust-lang#106164 - compiler-errors:check-region-tweak, r=oli-obk
Move `check_region_obligations_and_report_errors` to `TypeErrCtxt` Makes sense for this function to live with its sibling `resolve_regions_and_report_errors`, around which it's basically just a wrapper.
2 parents 78cff46 + c104ee9 commit 10529bc

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
@@ -615,7 +615,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
615615
Some(infcx),
616616
infcx.implied_bounds_tys(param_env, impl_m_hir_id, wf_tys),
617617
);
618-
infcx.check_region_obligations_and_report_errors(
618+
infcx.err_ctxt().check_region_obligations_and_report_errors(
619619
impl_m.def_id.expect_local(),
620620
&outlives_environment,
621621
)?;
@@ -1643,8 +1643,9 @@ pub(super) fn compare_impl_const_raw(
16431643
}
16441644

16451645
let outlives_environment = OutlivesEnvironment::new(param_env);
1646-
infcx.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment)?;
1647-
1646+
infcx
1647+
.err_ctxt()
1648+
.check_region_obligations_and_report_errors(impl_const_item_def, &outlives_environment)?;
16481649
Ok(())
16491650
}
16501651

@@ -1752,7 +1753,7 @@ fn compare_type_predicate_entailment<'tcx>(
17521753
// Finally, resolve all regions. This catches wily misuses of
17531754
// lifetime parameters.
17541755
let outlives_environment = OutlivesEnvironment::new(param_env);
1755-
infcx.check_region_obligations_and_report_errors(
1756+
infcx.err_ctxt().check_region_obligations_and_report_errors(
17561757
impl_ty.def_id.expect_local(),
17571758
&outlives_environment,
17581759
)?;
@@ -1966,7 +1967,7 @@ pub(super) fn check_type_bounds<'tcx>(
19661967
let outlives_environment =
19671968
OutlivesEnvironment::with_bounds(param_env, Some(&infcx), implied_bounds);
19681969

1969-
infcx.check_region_obligations_and_report_errors(
1970+
infcx.err_ctxt().check_region_obligations_and_report_errors(
19701971
impl_ty.def_id.expect_local(),
19711972
&outlives_environment,
19721973
)?;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

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

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

122124
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
@@ -1679,13 +1679,29 @@ impl<'tcx> InferCtxt<'tcx> {
16791679
}
16801680

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