Skip to content

Commit 251455b

Browse files
Allow WellFormed goals to be returned from relating in new solver
1 parent 90f5eab commit 251455b

File tree

3 files changed

+57
-7
lines changed

3 files changed

+57
-7
lines changed

Diff for: compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -971,15 +971,17 @@ where
971971
rhs: T,
972972
) -> Result<(), NoSolution> {
973973
let goals = self.delegate.relate(param_env, lhs, variance, rhs, self.origin_span)?;
974-
if cfg!(debug_assertions) {
975-
for g in goals.iter() {
976-
match g.predicate.kind().skip_binder() {
977-
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {}
978-
p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
974+
for &goal in goals.iter() {
975+
let source = match goal.predicate.kind().skip_binder() {
976+
ty::PredicateKind::Subtype { .. } | ty::PredicateKind::AliasRelate(..) => {
977+
GoalSource::TypeRelating
979978
}
980-
}
979+
// FIXME(-Znext-solver=coinductive): should these WF goals also be unproductive?
980+
ty::PredicateKind::Clause(ty::ClauseKind::WellFormed(_)) => GoalSource::Misc,
981+
p => unreachable!("unexpected nested goal in `relate`: {p:?}"),
982+
};
983+
self.add_goal(source, goal);
981984
}
982-
self.add_goals(GoalSource::TypeRelating, goals);
983985
Ok(())
984986
}
985987

Diff for: tests/ui/traits/next-solver/well-formed-in-relate.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
fn main() {
2+
let x;
3+
//~^ ERROR type annotations needed for `Map<_, _>`
4+
higher_ranked();
5+
x = unconstrained_map();
6+
}
7+
8+
fn higher_ranked() where for<'a> &'a (): Sized {}
9+
10+
struct Map<T, U> where T: Fn() -> U {
11+
t: T,
12+
}
13+
14+
trait Mirror {
15+
type Assoc;
16+
}
17+
impl<T> Mirror for T {
18+
type Assoc = T;
19+
}
20+
21+
fn unconstrained_map<T: Fn() -> U, U>() -> <Map<T, U> as Mirror>::Assoc { todo!() }
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0283]: type annotations needed for `Map<_, _>`
2+
--> $DIR/well-formed-in-relate.rs:2:9
3+
|
4+
LL | let x;
5+
| ^
6+
...
7+
LL | x = unconstrained_map();
8+
| ------------------- type must be known at this point
9+
|
10+
= note: multiple `impl`s satisfying `_: Fn()` found in the following crates: `alloc`, `core`:
11+
- impl<A, F> Fn<A> for &F
12+
where A: Tuple, F: Fn<A>, F: ?Sized;
13+
- impl<Args, F, A> Fn<Args> for Box<F, A>
14+
where Args: Tuple, F: Fn<Args>, A: Allocator, F: ?Sized;
15+
note: required by a bound in `unconstrained_map`
16+
--> $DIR/well-formed-in-relate.rs:21:25
17+
|
18+
LL | fn unconstrained_map<T: Fn() -> U, U>() -> <Map<T, U> as Mirror>::Assoc { todo!() }
19+
| ^^^^^^^^^ required by this bound in `unconstrained_map`
20+
help: consider giving `x` an explicit type, where the type for type parameter `T` is specified
21+
|
22+
LL | let x: Map<T, U>;
23+
| +++++++++++
24+
25+
error: aborting due to 1 previous error
26+
27+
For more information about this error, try `rustc --explain E0283`.

0 commit comments

Comments
 (0)