Skip to content

Commit c64bf00

Browse files
committed
add new_leaf functions
1 parent ce52903 commit c64bf00

3 files changed

Lines changed: 32 additions & 19 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 & 10 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();
@@ -285,6 +293,13 @@ impl<I: Interner> CanonicalFormRegionConstraint<I> {
285293
false
286294
}
287295
}
296+
297+
pub fn new_leaf(l: LeafRegionConstraint<I>) -> Self {
298+
CanonicalFormRegionConstraint {
299+
and_constraint: And(Box::new([l])),
300+
or_constraint: Or::new_true(),
301+
}
302+
}
288303
}
289304

290305
impl<I: Interner> Default for CanonicalFormRegionConstraint<I> {
@@ -509,21 +524,21 @@ fn pull_region_outlives_constraints_out_of_universe<
509524
match c {
510525
Ambiguity | PlaceholderTyOutlives(..) | AliasTyOutlivesViaEnv(..) => {
511526
assert!(max_universe(infcx, c.clone()) < u);
512-
pulled_constraints.push(Or::new([And::new([c.clone()])]));
527+
pulled_constraints.push(Or::new_leaf(c.clone()));
513528
}
514529
RegionOutlives(region_1, region_2) => {
515530
let region_1_u = max_universe(infcx, region_1);
516531
let region_2_u = max_universe(infcx, region_2);
517532

518533
if region_1_u != u && region_2_u != u {
519-
pulled_constraints.push(Or::new([And::new([c])]));
534+
pulled_constraints.push(Or::new_leaf(c));
520535
continue;
521536
}
522537

523538
let assumptions = match assumptions {
524539
Some(assumptions) => assumptions,
525540
None => {
526-
pulled_constraints.push(Or::new([And::new([Ambiguity])]));
541+
pulled_constraints.push(Or::new_ambig());
527542
continue;
528543
}
529544
};
@@ -588,7 +603,7 @@ pub fn destructure_type_outlives_constraints_in_root<
588603
let mut ors = Vec::new();
589604
for c in &and.0 {
590605
match c {
591-
Ambiguity | RegionOutlives(..) => ors.push(Or::new([And::new([c.clone()])])),
606+
Ambiguity | RegionOutlives(..) => ors.push(Or::new_leaf(c.clone())),
592607
PlaceholderTyOutlives(ty, r) => ors.push(Or::new(
593608
regions_outlived_by_placeholder(*ty, assumptions, infcx.cx())
594609
.map(move |assumption_r| And::new([RegionOutlives(assumption_r, *r)])),
@@ -651,7 +666,7 @@ fn rewrite_type_outlives_constraints_in_universe_for_eager_placeholder_handling<
651666
let mut ors = Vec::new();
652667
for c in and.0 {
653668
match c {
654-
Ambiguity | RegionOutlives(..) => ors.push(Or::new([And::new([c])])),
669+
Ambiguity | RegionOutlives(..) => ors.push(Or::new_leaf(c)),
655670
PlaceholderTyOutlives(ty, region) => {
656671
ors.push(rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder_handling(infcx, ty, region, u, assumptions));
657672
}
@@ -689,12 +704,12 @@ fn rewrite_placeholder_ty_outlives_constraints_in_universe_for_eager_placeholder
689704
let region_u = max_universe(infcx, region);
690705

691706
if region_u != u && ty_u != u {
692-
return Or::new([And::new([PlaceholderTyOutlives(ty, region)])]);
707+
return Or::new_leaf(PlaceholderTyOutlives(ty, region));
693708
}
694709

695710
let assumptions = match assumptions {
696711
Some(assumptions) => assumptions,
697-
None => return Or::new([And::new([Ambiguity])]),
712+
None => return Or::new_ambig(),
698713
};
699714

700715
let mut candidates = vec![];
@@ -766,13 +781,13 @@ fn rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handl
766781
escaping_outlives,
767782
I::BoundVarKinds::from_vars(infcx.cx(), bound_vars),
768783
);
769-
candidates.push(Or::new([And::new([AliasTyOutlivesViaEnv(bound_outlives)])]));
784+
candidates.push(Or::new_leaf(AliasTyOutlivesViaEnv(bound_outlives)));
770785
}
771786

772787
let assumptions = match assumptions {
773788
Some(assumptions) => assumptions,
774789
None => {
775-
candidates.push(Or::new([And::new([Ambiguity])]));
790+
candidates.push(Or::new_ambig());
776791
return candidates.into_iter().fold(Or::new_false(), |acc, c| Or::new_or(acc, c));
777792
}
778793
};
@@ -820,7 +835,7 @@ fn rewrite_alias_ty_outlives_constraints_in_universe_for_eager_placeholder_handl
820835
// let's be conservative and not let alias outlives' cause NoSolution
821836
// in coherence
822837
match infcx.typing_mode_raw() {
823-
TypingMode::Coherence => candidates.push(Or::new([And::new([Ambiguity])])),
838+
TypingMode::Coherence => candidates.push(Or::new_ambig()),
824839
TypingMode::Typeck { .. }
825840
| TypingMode::Reflection
826841
| TypingMode::ErasedNotCoherence { .. }

0 commit comments

Comments
 (0)