Skip to content

Commit

Permalink
Recurse on GAT where clauses in fulfillment error proof tree visitor
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jan 6, 2025
1 parent 2be9ffc commit ebdf19a
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 25 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_next_trait_solver/src/solve/effect_goals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ where
|ecx| {
// Const conditions must hold for the implied const bound to hold.
ecx.add_goals(
GoalSource::Misc,
GoalSource::AliasBoundConstCondition,
cx.const_conditions(alias_ty.def_id)
.iter_instantiated(cx, alias_ty.args)
.map(|trait_ref| {
Expand Down Expand Up @@ -353,7 +353,7 @@ where

ecx.probe_builtin_trait_candidate(BuiltinImplSource::Misc).enter(|ecx| {
ecx.add_goals(
GoalSource::ImplWhereBound,
GoalSource::AliasBoundConstCondition,
const_conditions.into_iter().map(|trait_ref| {
goal.with(
cx,
Expand Down
14 changes: 9 additions & 5 deletions compiler/rustc_trait_selection/src/solve/fulfill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ impl<'tcx> BestObligation<'tcx> {
matches!(
nested_goal.source(),
GoalSource::ImplWhereBound
| GoalSource::AliasBoundConstCondition
| GoalSource::InstantiateHigherRanked
| GoalSource::AliasWellFormed
) && match self.consider_ambiguities {
Expand Down Expand Up @@ -495,7 +496,6 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
};

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

Expand All @@ -521,21 +521,25 @@ impl<'tcx> ProofTreeVisitor<'tcx> for BestObligation<'tcx> {
));
impl_where_bound_count += 1;
}
(ChildMode::Host(parent_host_pred), GoalSource::ImplWhereBound) => {
(
ChildMode::Host(parent_host_pred),
GoalSource::ImplWhereBound | GoalSource::AliasBoundConstCondition,
) => {
obligation = make_obligation(derive_host_cause(
tcx,
candidate.kind(),
self.obligation.cause.clone(),
impl_const_condition_bound_count,
impl_where_bound_count,
parent_host_pred,
));
impl_const_condition_bound_count += 1;
impl_where_bound_count += 1;
}
// Skip over a higher-ranked predicate.
(_, GoalSource::InstantiateHigherRanked) => {
obligation = self.obligation.clone();
}
(ChildMode::PassThrough, _) | (_, GoalSource::AliasWellFormed) => {
(ChildMode::PassThrough, _)
| (_, GoalSource::AliasWellFormed | GoalSource::AliasBoundConstCondition) => {
obligation = make_obligation(self.obligation.cause.clone());
}
}
Expand Down
4 changes: 4 additions & 0 deletions compiler/rustc_type_ir/src/solve/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub enum GoalSource {
/// FIXME(-Znext-solver=coinductive): Explain how and why this
/// changes whether cycles are coinductive.
ImplWhereBound,
/// Const conditions that need to hold for `~const` alias bounds to hold.
///
/// FIXME(-Znext-solver=coinductive): Are these even coinductive?
AliasBoundConstCondition,
/// Instantiating a higher-ranked goal and re-proving it.
InstantiateHigherRanked,
/// Predicate required for an alias projection to be well-formed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | T::Assoc::<U>::func();
| ^^^^^^^^^^^^^

error[E0277]: the trait bound `U: ~const Other` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:27:5
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:26:5
|
LL | <T as Trait>::Assoc::<U>::func();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
error[E0277]: the trait bound `U: ~const Other` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:24:5
|
LL | T::Assoc::<U>::func();
| ^^^^^^^^^^^^^

error[E0277]: the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:27:5
error[E0277]: the trait bound `U: ~const Other` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail-2.rs:26:5
|
LL | <T as Trait>::Assoc::<U>::func();
| ^^^^^^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@ trait Other {}

const fn fails<T: ~const Trait, U: Other>() {
T::Assoc::<U>::func();
//[current]~^ ERROR the trait bound `U: ~const Other` is not satisfied
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
//~^ ERROR the trait bound `U: ~const Other` is not satisfied
<T as Trait>::Assoc::<U>::func();
//[current]~^ ERROR the trait bound `U: ~const Other` is not satisfied
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc<U>: ~const Trait` is not satisfied
//~^ ERROR the trait bound `U: ~const Other` is not satisfied
}

const fn works<T: ~const Trait, U: ~const Other>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ LL | T::Assoc::func();
| ^^^^^^^^

error[E0277]: the trait bound `T: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:20:5
--> $DIR/assoc-type-const-bound-usage-fail.rs:19:5
|
LL | <T as Trait>::Assoc::func();
| ^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
error[E0277]: the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
error[E0277]: the trait bound `T: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:17:5
|
LL | T::Assoc::func();
| ^^^^^^^^

error[E0277]: the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:20:5
error[E0277]: the trait bound `T: ~const Trait` is not satisfied
--> $DIR/assoc-type-const-bound-usage-fail.rs:19:5
|
LL | <T as Trait>::Assoc::func();
| ^^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ trait Trait {

const fn unqualified<T: Trait>() {
T::Assoc::func();
//[current]~^ ERROR the trait bound `T: ~const Trait` is not satisfied
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied
<T as Trait>::Assoc::func();
//[current]~^ ERROR the trait bound `T: ~const Trait` is not satisfied
//[next]~^^ ERROR the trait bound `<T as Trait>::Assoc: ~const Trait` is not satisfied
//~^ ERROR the trait bound `T: ~const Trait` is not satisfied
}

const fn works<T: ~const Trait>() {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/traits/const-traits/const-opaque.no.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ note: required by a bound in `bar`
LL | const fn bar<T: ~const Foo>(t: T) -> impl ~const Foo {
| ^^^^^^ required by this bound in `bar`

error[E0277]: the trait bound `impl Foo: const Foo` is not satisfied
error[E0277]: the trait bound `(): const Foo` is not satisfied
--> $DIR/const-opaque.rs:33:12
|
LL | opaque.method();
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/traits/const-traits/const-opaque.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const _: () = {
let opaque = bar(());
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
opaque.method();
//[no]~^ ERROR the trait bound `impl Foo: const Foo` is not satisfied
//[no]~^ ERROR the trait bound `(): const Foo` is not satisfied
std::mem::forget(opaque);
};

Expand Down

0 comments on commit ebdf19a

Please sign in to comment.