Skip to content

Commit f591f53

Browse files
committed
lazily init SolverRegionConstraintStorage on access
1 parent 598fa63 commit f591f53

2 files changed

Lines changed: 8 additions & 6 deletions

File tree

compiler/rustc_infer/src/infer/solver_region_constraints.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@ use super::InferCtxt;
88
pub type SolverRegionConstraint<'tcx> = RegionConstraint<TyCtxt<'tcx>, Span>;
99

1010
#[derive(Clone, Debug)]
11-
pub(crate) struct SolverRegionConstraintStorage<'tcx>(SolverRegionConstraint<'tcx>);
11+
pub(crate) struct SolverRegionConstraintStorage<'tcx>(Option<SolverRegionConstraint<'tcx>>);
1212

1313
impl<'tcx> SolverRegionConstraintStorage<'tcx> {
1414
pub(crate) fn new() -> Self {
15-
Self(SolverRegionConstraint::new_true())
15+
Self(None)
1616
}
1717

1818
pub(crate) fn get_constraint(&self) -> SolverRegionConstraint<'tcx> {
19-
self.0.clone()
19+
self.0.clone().unwrap_or_default()
2020
}
2121

2222
pub(crate) fn take(&mut self) -> SolverRegionConstraint<'tcx> {
23-
core::mem::replace(&mut self.0, SolverRegionConstraint::new_true())
23+
self.0.take().unwrap_or_default()
2424
}
2525

2626
#[instrument(level = "debug", skip(self))]
2727
pub(crate) fn overwrite(&mut self, constraint: SolverRegionConstraint<'tcx>) {
28-
self.0 = constraint;
28+
self.0 = Some(constraint);
2929
}
3030
}
3131

compiler/rustc_type_ir/src/region_constraint.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,9 @@ impl<I: Interner, S: Clone + std::fmt::Debug + Eq + std::hash::Hash> RegionConst
481481
}
482482
}
483483

484-
impl<I: Interner> Default for RegionConstraint<I> {
484+
impl<I: Interner, S: Clone + std::fmt::Debug + Eq + std::hash::Hash> Default
485+
for RegionConstraint<I, S>
486+
{
485487
fn default() -> Self {
486488
Self::new_true()
487489
}

0 commit comments

Comments
 (0)