Skip to content

Commit 74f87b0

Browse files
committed
add new_leaf functions
1 parent 4468c5c commit 74f87b0

3 files changed

Lines changed: 32 additions & 21 deletions

File tree

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/solver_region_constraints.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,12 +171,12 @@ where
171171
use Component::*;
172172
use LeafRegionConstraint::*;
173173
match c {
174-
Region(c_r) => Or::new([And::new([RegionOutlives(*c_r, r)])]),
174+
Region(c_r) => Or::new_leaf(RegionOutlives(*c_r, r)),
175175
Placeholder(p) => {
176-
Or::new([And::new([PlaceholderTyOutlives(Ty::new_placeholder(self.cx(), *p), r)])])
176+
Or::new_leaf(PlaceholderTyOutlives(Ty::new_placeholder(self.cx(), *p), r))
177177
}
178178
Alias(_, alias) => self.destructure_alias_outlives(*alias, r),
179-
UnresolvedInferenceVariable(_) => Or::new([And::new([Ambiguity])]),
179+
UnresolvedInferenceVariable(_) => Or::new_ambig(),
180180
Param(_) => panic!("Params should have been canonicalized to placeholders"),
181181
EscapingAlias(components) => self.destructure_components(components, r),
182182
}
@@ -198,8 +198,7 @@ where
198198
.map(|bound| And::new([RegionOutlives(bound, r)]));
199199
let item_bound_outlives = Or::new(item_bounds);
200200

201-
let where_clause_outlives =
202-
Or::new([And::new([AliasTyOutlivesViaEnv(Binder::dummy((alias, r)))])]);
201+
let where_clause_outlives = Or::new_leaf(AliasTyOutlivesViaEnv(Binder::dummy((alias, r))));
203202

204203
let mut components = Default::default();
205204
rustc_type_ir::outlives::compute_alias_components_recursive(

compiler/rustc_next_trait_solver/src/solve/mod.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,11 @@ where
124124

125125
if self.cx().assumptions_on_binders() {
126126
use rustc_type_ir::region_constraint::{
127-
And, CanonicalFormRegionConstraint, LeafRegionConstraint, Or,
127+
CanonicalFormRegionConstraint, LeafRegionConstraint,
128128
};
129129

130-
let constraint = CanonicalFormRegionConstraint::new_from_or(Or::new([And::new([
131-
LeafRegionConstraint::RegionOutlives(a, b),
132-
])]));
130+
let constraint =
131+
CanonicalFormRegionConstraint::new_leaf(LeafRegionConstraint::RegionOutlives(a, b));
133132
self.register_solver_region_constraint(constraint);
134133
} else {
135134
self.register_region_outlives(a, b, VisibleForLeakCheck::Yes);

compiler/rustc_type_ir/src/region_constraint.rs

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ impl<I: Interner> Or<I> {
160160
Self(new_ands.into_boxed_slice())
161161
}
162162

163+
pub fn new_ambig() -> Self {
164+
Or::new_leaf(LeafRegionConstraint::Ambiguity)
165+
}
166+
167+
pub fn new_leaf(l: LeafRegionConstraint<I>) -> Self {
168+
Or(Box::new([And(Box::new([l]))]))
169+
}
170+
163171
pub fn new_and(a: Or<I>, b: Or<I>) -> Self {
164172
// I think this returns false if either a or b is false?
165173
let mut ands = Vec::new();
@@ -291,6 +299,13 @@ impl<I: Interner> CanonicalFormRegionConstraint<I> {
291299
false
292300
}
293301
}
302+
303+
pub fn new_leaf(l: LeafRegionConstraint<I>) -> Self {
304+
CanonicalFormRegionConstraint {
305+
and_constraint: And(Box::new([l])),
306+
or_constraint: Or::new_true(),
307+
}
308+
}
294309
}
295310

296311
impl<I: Interner> Default for CanonicalFormRegionConstraint<I> {
@@ -485,21 +500,21 @@ fn pull_region_outlives_constraints_out_of_universe<
485500
match c {
486501
Ambiguity | PlaceholderTyOutlives(..) | AliasTyOutlivesViaEnv(..) => {
487502
assert!(max_universe(infcx, c.clone()) < u);
488-
pulled_constraints.push(Or::new([And::new([c.clone()])]));
503+
pulled_constraints.push(Or::new_leaf(c.clone()));
489504
}
490505
RegionOutlives(region_1, region_2) => {
491506
let region_1_u = max_universe(infcx, region_1);
492507
let region_2_u = max_universe(infcx, region_2);
493508

494509
if region_1_u != u && region_2_u != u {
495-
pulled_constraints.push(Or::new([And::new([c])]));
510+
pulled_constraints.push(Or::new_leaf(c));
496511
continue;
497512
}
498513

499514
let assumptions = match assumptions {
500515
Some(assumptions) => assumptions,
501516
None => {
502-
pulled_constraints.push(Or::new([And::new([Ambiguity])]));
517+
pulled_constraints.push(Or::new_ambig());
503518
continue;
504519
}
505520
};
@@ -558,7 +573,7 @@ pub fn destructure_type_outlives_constraints_in_root<
558573
for c in &and.0 {
559574
match c {
560575
Ambiguity | RegionOutlives(..) => {
561-
destructured_constraints.push(Or::new([And::new([c.clone()])]))
576+
destructured_constraints.push(Or::new_leaf(c.clone()))
562577
}
563578
PlaceholderTyOutlives(ty, r) => destructured_constraints.push(Or::new(
564579
regions_outlived_by_placeholder(*ty, assumptions, infcx.cx())
@@ -623,9 +638,7 @@ fn rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling<
623638
let mut rewritten_constraints = Vec::new();
624639
for c in and.0 {
625640
match c {
626-
Ambiguity | RegionOutlives(..) => {
627-
rewritten_constraints.push(Or::new([And::new([c])]))
628-
}
641+
Ambiguity | RegionOutlives(..) => rewritten_constraints.push(Or::new_leaf(c)),
629642
PlaceholderTyOutlives(ty, region) => {
630643
rewritten_constraints.push(rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder_handling(infcx, ty, region, u, assumptions));
631644
}
@@ -663,12 +676,12 @@ fn rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder
663676
let region_u = max_universe(infcx, region);
664677

665678
if region_u != u && ty_u != u {
666-
return Or::new([And::new([PlaceholderTyOutlives(ty, region)])]);
679+
return Or::new_leaf(PlaceholderTyOutlives(ty, region));
667680
}
668681

669682
let assumptions = match assumptions {
670683
Some(assumptions) => assumptions,
671-
None => return Or::new([And::new([Ambiguity])]),
684+
None => return Or::new_ambig(),
672685
};
673686

674687
let mut candidates = vec![];
@@ -740,13 +753,13 @@ fn rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handl
740753
escaping_outlives,
741754
I::BoundVarKinds::from_vars(infcx.cx(), bound_vars),
742755
);
743-
candidates.push(Or::new([And::new([AliasTyOutlivesViaEnv(bound_outlives)])]));
756+
candidates.push(Or::new_leaf(AliasTyOutlivesViaEnv(bound_outlives)));
744757
}
745758

746759
let assumptions = match assumptions {
747760
Some(assumptions) => assumptions,
748761
None => {
749-
candidates.push(Or::new([And::new([Ambiguity])]));
762+
candidates.push(Or::new_ambig());
750763
return candidates.into_iter().fold(Or::new_false(), |acc, c| Or::new_or(acc, c));
751764
}
752765
};
@@ -794,7 +807,7 @@ fn rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handl
794807
// let's be conservative and not let alias outlives' cause NoSolution
795808
// in coherence
796809
match infcx.typing_mode_raw() {
797-
TypingMode::Coherence => candidates.push(Or::new([And::new([Ambiguity])])),
810+
TypingMode::Coherence => candidates.push(Or::new_ambig()),
798811
TypingMode::Typeck { .. }
799812
| TypingMode::Reflection
800813
| TypingMode::ErasedNotCoherence { .. }

0 commit comments

Comments
 (0)