Auto merge of #142746 - compiler-errors:super-implied-outlives, r=lcnr

Apply `impl_super_outlives` optimization to new trait solver

I never did rust-lang/rust#128746 for the new solver.

r? lcnr
This commit is contained in:
bors
2025-06-25 10:10:21 +00:00
3 changed files with 20 additions and 9 deletions
+7
View File
@@ -432,6 +432,13 @@ fn explicit_implied_predicates_of(
self.explicit_implied_predicates_of(def_id).map_bound(|preds| preds.into_iter().copied())
}
fn impl_super_outlives(
self,
impl_def_id: DefId,
) -> ty::EarlyBinder<'tcx, impl IntoIterator<Item = ty::Clause<'tcx>>> {
self.impl_super_outlives(impl_def_id)
}
fn impl_is_const(self, def_id: DefId) -> bool {
debug_assert_matches!(self.def_kind(def_id), DefKind::Impl { of_trait: true });
self.is_conditionally_const(def_id)
@@ -103,15 +103,12 @@ fn consider_impl_candidate(
// We currently elaborate all supertrait outlives obligations from impls.
// This can be removed when we actually do coinduction correctly, and prove
// all supertrait obligations unconditionally.
let goal_clause: I::Clause = goal.predicate.upcast(cx);
for clause in elaborate::elaborate(cx, [goal_clause]) {
if matches!(
clause.kind().skip_binder(),
ty::ClauseKind::TypeOutlives(..) | ty::ClauseKind::RegionOutlives(..)
) {
ecx.add_goal(GoalSource::Misc, goal.with(cx, clause));
}
}
ecx.add_goals(
GoalSource::Misc,
cx.impl_super_outlives(impl_def_id)
.iter_instantiated(cx, impl_args)
.map(|pred| goal.with(cx, pred)),
);
ecx.evaluate_added_goals_and_make_canonical_response(maximal_certainty)
})
+7
View File
@@ -271,6 +271,13 @@ fn explicit_implied_predicates_of(
def_id: Self::DefId,
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = (Self::Clause, Self::Span)>>;
/// This is equivalent to computing the super-predicates of the trait for this impl
/// and filtering them to the outlives predicates. This is purely for performance.
fn impl_super_outlives(
self,
impl_def_id: Self::DefId,
) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
fn impl_is_const(self, def_id: Self::DefId) -> bool;
fn fn_is_const(self, def_id: Self::DefId) -> bool;
fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool;