Skip to content

Commit c96ba49

Browse files
Mark const condition where clauses as where clauses, and treat Host predicates like Trait predicates in new solver diagnostic visitor
1 parent a0d98ff commit c96ba49

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ where
101101
|ecx| {
102102
// Const conditions must hold for the implied const bound to hold.
103103
ecx.add_goals(
104-
GoalSource::Misc,
104+
// FIXME: Are these where clauses? Yes?
105+
GoalSource::ImplWhereBound,
105106
cx.const_conditions(alias_ty.def_id)
106107
.iter_instantiated(cx, alias_ty.args)
107108
.map(|trait_ref| {

compiler/rustc_trait_selection/src/solve/fulfill.rs

+15-3
Original file line numberDiff line numberDiff line change
@@ -461,8 +461,11 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
461461
// for normalizes-to.
462462
let pred_kind = goal.goal().predicate.kind();
463463
let child_mode = match pred_kind.skip_binder() {
464-
ty::PredicateKind::Clause(ty::ClauseKind::Trait(parent_trait_pred)) => {
465-
ChildMode::Trait(pred_kind.rebind(parent_trait_pred))
464+
ty::PredicateKind::Clause(ty::ClauseKind::Trait(pred)) => {
465+
ChildMode::Trait(pred_kind.rebind(pred))
466+
}
467+
ty::PredicateKind::Clause(ty::ClauseKind::HostEffect(pred)) => {
468+
ChildMode::Host(pred_kind.rebind(pred))
466469
}
467470
ty::PredicateKind::NormalizesTo(normalizes_to)
468471
if matches!(
@@ -491,7 +494,7 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
491494

492495
let obligation;
493496
match (child_mode, nested_goal.source()) {
494-
(ChildMode::Trait(_), GoalSource::Misc) => {
497+
(ChildMode::Trait(_) | ChildMode::Host(_), GoalSource::Misc) => {
495498
continue;
496499
}
497500
(ChildMode::Trait(parent_trait_pred), GoalSource::ImplWhereBound) => {
@@ -504,6 +507,10 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
504507
));
505508
impl_where_bound_count += 1;
506509
}
510+
(ChildMode::Host(_), GoalSource::ImplWhereBound) => {
511+
// TODO:
512+
obligation = make_obligation(self.obligation.cause.clone());
513+
}
507514
// Skip over a higher-ranked predicate.
508515
(_, GoalSource::InstantiateHigherRanked) => {
509516
obligation = self.obligation.clone();
@@ -562,6 +569,11 @@ enum ChildMode<'tcx> {
562569
// and skip all `GoalSource::Misc`, which represent useless obligations
563570
// such as alias-eq which may not hold.
564571
Trait(ty::PolyTraitPredicate<'tcx>),
572+
// Try to derive an `ObligationCause::{ImplDerived,BuiltinDerived}`,
573+
// and skip all `GoalSource::Misc`, which represent useless obligations
574+
// such as alias-eq which may not hold.
575+
#[expect(dead_code)]
576+
Host(ty::Binder<'tcx, ty::HostEffectPredicate<'tcx>>),
565577
// Skip trying to derive an `ObligationCause` from this obligation, and
566578
// report *all* sub-obligations as if they came directly from the parent
567579
// obligation.

tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ trait Other {}
2222

2323
const fn fails<T: ~const Trait, U: Other>() {
2424
T::Assoc::<U>::func();
25-
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
25+
//~^ ERROR the trait bound `U: ~const Other` is not satisfied
2626
<T as Trait>::Assoc::<U>::func();
27-
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
27+
//~^ ERROR the trait bound `U: ~const Other` is not satisfied
2828
}
2929

3030
const fn works<T: ~const Trait, U: ~const Other>() {

tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail-2.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
1+
error[E0277]: the trait bound `U: ~const Other` is not satisfied
22
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:24:5
33
|
44
LL | T::Assoc::<U>::func();
55
| ^^^^^^^^^^^^^^^^^^^^^
66

7-
error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
7+
error[E0277]: the trait bound `U: ~const Other` is not satisfied
88
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:26:5
99
|
1010
LL | <T as Trait>::Assoc::<U>::func();

0 commit comments

Comments
 (0)