Skip to content

Commit 525cdc7

Browse files
committed
skip checking supertraits in assembly_object_bound_candidate for NormalizesTo goal
1 parent fb505a7 commit 525cdc7

File tree

3 files changed

+55
-0
lines changed

3 files changed

+55
-0
lines changed

compiler/rustc_next_trait_solver/src/solve/assembly/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ where
7474
/// Consider a clause specifically for a `dyn Trait` self type. This requires
7575
/// additionally checking all of the supertraits and object bounds to hold,
7676
/// since they're not implied by the well-formedness of the object type.
77+
/// `NormalizesTo` overrides this to not check the supertraits for backwards
78+
/// compatibility with the old solver. cc trait-system-refactor-initiative#245.
7779
fn probe_and_consider_object_bound_candidate(
7880
ecx: &mut EvalCtxt<'_, D>,
7981
source: CandidateSource<I>,

compiler/rustc_next_trait_solver/src/solve/normalizes_to/mod.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ where
184184
then(ecx)
185185
}
186186

187+
// Hack for trait-system-refactor-initiative#245.
188+
// FIXME(-Zhigher-ranked-assumptions): this impl differs from trait goals and we should unify
189+
// them again once we properly support binders.
190+
fn probe_and_consider_object_bound_candidate(
191+
ecx: &mut EvalCtxt<'_, D>,
192+
source: CandidateSource<I>,
193+
goal: Goal<I, Self>,
194+
assumption: I::Clause,
195+
) -> Result<Candidate<I>, NoSolution> {
196+
Self::probe_and_match_goal_against_assumption(ecx, source, goal, assumption, |ecx| {
197+
ecx.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
198+
})
199+
}
200+
187201
fn consider_additional_alias_assumptions(
188202
_ecx: &mut EvalCtxt<'_, D>,
189203
_goal: Goal<I, Self>,
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ check-pass
2+
//@ compile-flags: -Znext-solver
3+
//@ edition: 2024
4+
5+
// A regression test for trait-system-refactor-initiative#245.
6+
// The old solver doesn't check the supertraits of the principal trait
7+
// when considering object candidate for normalization.
8+
// And the new solver previously did, resulting in a placeholder error
9+
// while normalizing inside of a generator witness.
10+
11+
trait AsyncFn: Send + 'static {
12+
type Fut: Future<Output = ()> + Send;
13+
14+
fn call(&self) -> Self::Fut;
15+
}
16+
17+
type BoxFuture<'a, T> = std::pin::Pin<Box<dyn Future<Output = T> + Send + 'a>>;
18+
type DynAsyncFnBoxed = dyn AsyncFn<Fut = BoxFuture<'static, ()>>;
19+
20+
fn wrap_call<P: AsyncFn + ?Sized>(func: Box<P>) -> impl Future<Output = ()> {
21+
func.call()
22+
}
23+
24+
fn get_boxed_fn() -> Box<DynAsyncFnBoxed> {
25+
todo!()
26+
}
27+
28+
async fn cursed_fut() {
29+
wrap_call(get_boxed_fn()).await;
30+
}
31+
32+
fn observe_fut_not_send() {
33+
fn assert_send<T: Send>(t: T) -> T {
34+
t
35+
}
36+
assert_send(cursed_fut());
37+
}
38+
39+
fn main() {}

0 commit comments

Comments
 (0)