Skip to content

Commit 360bd32

Browse files
Recurse on GAT where clauses in fulfillment error proof tree visitor
1 parent c439226 commit 360bd32

File tree

9 files changed

+25
-17
lines changed

9 files changed

+25
-17
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.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ trait Other {}
2121

2222
const fn fails<T: ~const Trait, U: Other>() {
2323
T::Assoc::<U>::func();
24-
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
24+
//~^ ERROR the trait bound `U: ~const Other` is not satisfied
2525
<T as Trait>::Assoc::<U>::func();
26-
//~^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
26+
//~^ ERROR the trait bound `U: ~const Other` is not satisfied
2727
}
2828

2929
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:23: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:25:5
99
|
1010
LL | <T as Trait>::Assoc::<U>::func();

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ trait Trait {
1414

1515
const fn unqualified<T: Trait>() {
1616
T::Assoc::func();
17-
//~^ ERROR the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
17+
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied
1818
<T as Trait>::Assoc::func();
19-
//~^ ERROR the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
19+
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied
2020
}
2121

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

tests/ui/traits/const-traits/assoc-type-const-bound-usage-fail.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: ~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:16:5
33
|
44
LL | T::Assoc::func();
55
| ^^^^^^^^
66

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

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)