Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions compiler/rustc_infer/src/infer/solver_region_constraints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,23 @@ pub type SolverRegionConstraint<'tcx> =
rustc_type_ir::region_constraint::RegionConstraint<TyCtxt<'tcx>, Span>;

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

impl<'tcx> SolverRegionConstraintStorage<'tcx> {
pub(crate) fn new() -> Self {
Self(SolverRegionConstraint::new_true())
Self(None)
}

pub(crate) fn get_constraint(&self) -> SolverRegionConstraint<'tcx> {
self.0.clone()
match &self.0 {
Some(v) => v.clone(),
None => SolverRegionConstraint::new_true(),
}
}

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

Expand Down
20 changes: 9 additions & 11 deletions compiler/rustc_type_ir/src/region_constraint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ impl<I: Interner> Or<I> {
}
impl<I: Interner, S: Clone + std::hash::Hash + std::fmt::Debug + Eq> Or<I, S> {
pub fn new_true() -> Self {
Self(Box::new([And::new([])]))
Self(Box::new([And::new_true()]))
}

pub fn is_true(&self) -> bool {
Expand Down Expand Up @@ -323,6 +323,10 @@ impl<I: Interner> And<I> {
}
}
impl<I: Interner, S: Clone + std::hash::Hash + std::fmt::Debug + Eq> And<I, S> {
pub fn new_true() -> Self {
Self(Box::new([]))
}

pub fn new(i: impl IntoIterator<Item = LeafRegionConstraint<I, S>>) -> Self {
let mut seen = IndexSet::new();
And(i
Expand Down Expand Up @@ -406,7 +410,7 @@ impl<I: Interner, S: Clone + std::fmt::Debug + Eq + std::hash::Hash> RegionConst
}));

Self {
and_constraint: if or_constraint.is_false() { And::new([]) } else { and_constraint },
and_constraint: if or_constraint.is_false() { And::new_true() } else { and_constraint },
or_constraint,
}
}
Expand All @@ -422,7 +426,7 @@ impl<I: Interner, S: Clone + std::fmt::Debug + Eq + std::hash::Hash> RegionConst
let or_constraint = Or::build_and(a.or_constraint, b.or_constraint);

Self {
and_constraint: if or_constraint.is_false() { And::new([]) } else { and_constraint },
and_constraint: if or_constraint.is_false() { And::new_true() } else { and_constraint },
or_constraint,
}
}
Expand All @@ -432,15 +436,15 @@ impl<I: Interner, S: Clone + std::fmt::Debug + Eq + std::hash::Hash> RegionConst
}

pub fn new_true() -> Self {
Self { and_constraint: And::new([]), or_constraint: Or::new_true() }
Self { and_constraint: And::new_true(), or_constraint: Or::new_true() }
}

pub fn is_true(&self) -> bool {
self.and_constraint.0.is_empty() && self.or_constraint.is_true()
}

pub fn new_false() -> Self {
Self { and_constraint: And::new([]), or_constraint: Or::new_false() }
Self { and_constraint: And::new_true(), or_constraint: Or::new_false() }
}

pub fn is_false(&self) -> bool {
Expand Down Expand Up @@ -477,12 +481,6 @@ impl<I: Interner, S: Clone + std::fmt::Debug + Eq + std::hash::Hash> RegionConst
}
}

impl<I: Interner> Default for RegionConstraint<I> {
fn default() -> Self {
Self::new_true()
}
}

impl<I: Interner, S: Clone + std::fmt::Debug> LeafRegionConstraint<I, S> {
pub fn is_ambig(&self) -> bool {
matches!(self, Self::Ambiguity(_))
Expand Down
Loading