Skip to content

Commit ebdf19a

Browse files
Recurse on GAT where clauses in fulfillment error proof tree visitor
1 parent 2be9ffc commit ebdf19a

11 files changed

+29
-25
lines changed

compiler/rustc_next_trait_solver/src/solve/effect_goals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ where
103103
|ecx| {
104104
// Const conditions must hold for the implied const bound to hold.
105105
ecx.add_goals(
106-
GoalSource::Misc,
106+
GoalSource::AliasBoundConstCondition,
107107
cx.const_conditions(alias_ty.def_id)
108108
.iter_instantiated(cx, alias_ty.args)
109109
.map(|trait_ref| {
@@ -353,7 +353,7 @@ where
353353

354354
ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
355355
ecx.add_goals(
356-
GoalSource::ImplWhereBound,
356+
GoalSource::AliasBoundConstCondition,
357357
const_conditions.into_iter().map(|trait_ref| {
358358
goal.with(
359359
cx,

compiler/rustc_trait_selection/src/solve/fulfill.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ impl<'tcx> BestObligation<'tcx> {
413413
matches!(
414414
nested_goal.source(),
415415
GoalSource::ImplWhereBound
416+
| GoalSource::AliasBoundConstCondition
416417
| GoalSource::InstantiateHigherRanked
417418
| GoalSource::AliasWellFormed
418419
) && match self.consider_ambiguities {
@@ -495,7 +496,6 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
495496
};
496497

497498
let mut impl_where_bound_count = 0;
498-
let mut impl_const_condition_bound_count = 0;
499499
for nested_goal in candidate.instantiate_nested_goals(self.span()) {
500500
trace!(nested_goal = ?(nested_goal.goal(), nested_goal.source(), nested_goal.result()));
501501

@@ -521,21 +521,25 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
521521
));
522522
impl_where_bound_count += 1;
523523
}
524-
(ChildMode::Host(parent_host_pred), GoalSource::ImplWhereBound) => {
524+
(
525+
ChildMode::Host(parent_host_pred),
526+
GoalSource::ImplWhereBound | GoalSource::AliasBoundConstCondition,
527+
) => {
525528
obligation = make_obligation(derive_host_cause(
526529
tcx,
527530
candidate.kind(),
528531
self.obligation.cause.clone(),
529-
impl_const_condition_bound_count,
532+
impl_where_bound_count,
530533
parent_host_pred,
531534
));
532-
impl_const_condition_bound_count += 1;
535+
impl_where_bound_count += 1;
533536
}
534537
// Skip over a higher-ranked predicate.
535538
(_, GoalSource::InstantiateHigherRanked) => {
536539
obligation = self.obligation.clone();
537540
}
538-
(ChildMode::PassThrough, _) | (_, GoalSource::AliasWellFormed) => {
541+
(ChildMode::PassThrough, _)
542+
| (_, GoalSource::AliasWellFormed | GoalSource::AliasBoundConstCondition) => {
539543
obligation = make_obligation(self.obligation.cause.clone());
540544
}
541545
}

compiler/rustc_type_ir/src/solve/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ pub enum GoalSource {
6868
/// FIXME(-Znext-solver=coinductive): Explain how and why this
6969
/// changes whether cycles are coinductive.
7070
ImplWhereBound,
71+
/// Const conditions that need to hold for `~const` alias bounds to hold.
72+
///
73+
/// FIXME(-Znext-solver=coinductive): Are these even coinductive?
74+
AliasBoundConstCondition,
7175
/// Instantiating a higher-ranked goal and re-proving it.
7276
InstantiateHigherRanked,
7377
/// Predicate required for an alias projection to be well-formed.

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | T::Assoc::<U>::func();
55
| ^^^^^^^^^^^^^
66

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

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
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
8-
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:27:5
7+
error[E0277]: the trait bound `U: ~const Other` is not satisfied
8+
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:26:5
99
|
1010
LL | <T as Trait>::Assoc::<U>::func();
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^

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

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

2323
const fn fails<T: ~const Trait, U: Other>() {
2424
T::Assoc::<U>::func();
25-
//[current]~^ ERROR the trait bound `U: ~const Other` is not satisfied
26-
//[next]~^^ 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
2726
<T as Trait>::Assoc::<U>::func();
28-
//[current]~^ ERROR the trait bound `U: ~const Other` is not satisfied
29-
//[next]~^^ 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
3028
}
3129

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | T::Assoc::func();
55
| ^^^^^^^^
66

77
error[E0277]: the trait bound `T: ~const Trait` is not satisfied
8-
--> $DIR/assoc-type-const-bound-usage-fail.rs:20:5
8+
--> $DIR/assoc-type-const-bound-usage-fail.rs:19:5
99
|
1010
LL | <T as Trait>::Assoc::func();
1111
| ^^^^^^^^^^^^^^^^^^^

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

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

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

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ trait Trait {
1515

1616
const fn unqualified<T: Trait>() {
1717
T::Assoc::func();
18-
//[current]~^ ERROR the trait bound `T: ~const Trait` is not satisfied
19-
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
18+
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied
2019
<T as Trait>::Assoc::func();
21-
//[current]~^ ERROR the trait bound `T: ~const Trait` is not satisfied
22-
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
20+
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied
2321
}
2422

2523
const fn works<T: ~const Trait>() {

tests/ui/traits/const-traits/const-opaque.no.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ note: required by a bound in `bar`
1212
LL | const fn bar<T: ~const Foo>(t: T) -> impl ~const Foo {
1313
| ^^^^^^ required by this bound in `bar`
1414

15-
error[E0277]: the trait bound `impl Foo: const Foo` is not satisfied
15+
error[E0277]: the trait bound `(): const Foo` is not satisfied
1616
--> $DIR/const-opaque.rs:33:12
1717
|
1818
LL | opaque.method();

tests/ui/traits/const-traits/const-opaque.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const _: () = {
3131
let opaque = bar(());
3232
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
3333
opaque.method();
34-
//[no]~^ ERROR the trait bound `impl Foo: const Foo` is not satisfied
34+
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
3535
std::mem::forget(opaque);
3636
};
3737

0 commit comments

Comments
 (0)