Skip to content

Commit 80e598b

Browse files
committed
clone region obligations instead of taking in implied bounds hack
1 parent 817e181 commit 80e598b

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ impl<'tcx> InferCtxt<'tcx> {
170170
std::mem::take(&mut self.inner.borrow_mut().region_obligations)
171171
}
172172

173+
pub fn clone_registered_region_obligations(&self) -> Vec<TypeOutlivesConstraint<'tcx>> {
174+
self.inner.borrow().region_obligations.clone()
175+
}
176+
173177
pub fn register_region_assumption(&self, assumption: ty::ArgOutlivesPredicate<'tcx>) {
174178
let mut inner = self.inner.borrow_mut();
175179
inner.undo_log.push(UndoLog::PushRegionAssumption);

compiler/rustc_trait_selection/src/traits/query/type_op/implied_outlives_bounds.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
5555
span: Span,
5656
disable_implied_bounds_hack: bool,
5757
) -> Result<Vec<OutlivesBound<'tcx>>, NoSolution> {
58+
// Inside mir borrowck, each computation starts with an empty list.
59+
assert!(
60+
ocx.infcx.inner.borrow().region_obligations().is_empty(),
61+
"compute_implied_outlives_bounds assumes region obligations are empty before starting"
62+
);
63+
5864
let normalize_ty = |ty| -> Result<_, NoSolution> {
5965
// We must normalize the type so we can compute the right outlives components.
6066
// for example, if we have some constrained param type like `T: Trait<Out = U>`,
@@ -143,7 +149,7 @@ pub fn compute_implied_outlives_bounds_inner<'tcx>(
143149
&& ty.visit_with(&mut ContainsBevyParamSet { tcx: ocx.infcx.tcx }).is_break()
144150
{
145151
for TypeOutlivesConstraint { sup_type, sub_region, .. } in
146-
ocx.infcx.take_registered_region_obligations()
152+
ocx.infcx.clone_registered_region_obligations()
147153
{
148154
let mut components = smallvec![];
149155
push_outlives_components(ocx.infcx.tcx, sup_type, &mut components);

0 commit comments

Comments
 (0)