Allow WellFormed goals to be returned from relating in new solver

This commit is contained in:
Michael Goulet 2025-03-23 18:56:34 +00:00
parent 90f5eab952
commit 251455bcc5
3 changed files with 57 additions and 7 deletions

View file

@ -971,15 +971,17 @@ where
rhs: T,
) -> Result<(), NoSolution> {
let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
if cfg!(debug_assertions) {
for g in goals.iter() {
match g.predicate.kind().skip_binder() {
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {}
p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
for &goal in goals.iter() {
let source = match goal.predicate.kind().skip_binder() {
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {
GoalSource::TypeRelating
}
}
// FIXME(-Znext-solver=coinductive): should these WF goals also be unproductive?
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
};
self.add_goal(source, goal);
}
self.add_goals(GoalSource::TypeRelating, goals);
Ok(())
}

View file

@ -0,0 +1,21 @@
fn main() {
let x;
//~^ ERROR type annotations needed for `Map<_, _>`
higher_ranked();
x = unconstrained_map();
}
fn higher_ranked() where for<'a> &'a (): Sized {}
struct Map<T, U> where T: Fn() -> U {
t: T,
}
trait Mirror {
type Assoc;
}
impl<T> Mirror for T {
type Assoc = T;
}
fn unconstrained_map<T: Fn() -> U, U>() -> <Map<T, U> as Mirror>::Assoc { todo!() }

View file

@ -0,0 +1,27 @@
error[E0283]: type annotations needed for `Map<_, _>`
--> $DIR/well-formed-in-relate.rs:2:9
|
LL | let x;
| ^
...
LL | x = unconstrained_map();
| ------------------- type must be known at this point
|
= note: multiple `impl`s satisfying `_: Fn()` found in the following crates: `alloc`, `core`:
- impl<A, F> Fn<A> for &F
where A: Tuple, F: Fn<A>, F: ?Sized;
- impl<Args, F, A> Fn<Args> for Box<F, A>
where Args: Tuple, F: Fn<Args>, A: Allocator, F: ?Sized;
note: required by a bound in `unconstrained_map`
--> $DIR/well-formed-in-relate.rs:21:25
|
LL | fn unconstrained_map<T: Fn() -> U, U>() -> <Map<T, U> as Mirror>::Assoc { todo!() }
| ^^^^^^^^^ required by this bound in `unconstrained_map`
help: consider giving `x` an explicit type, where the type for type parameter `T` is specified
|
LL | let x: Map<T, U>;
| +++++++++++
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0283`.