Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit c4c54df

Browse files
committedApr 16, 2025·
Don't require rigid alias's trait to hold
1 parent afa859f commit c4c54df

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed
 

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

-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ where
4545
goal,
4646
goal.predicate.alias,
4747
);
48-
this.add_goal(GoalSource::AliasWellFormed, goal.with(cx, trait_ref));
4948
this.evaluate_added_goals_and_make_canonical_response(Certainty::Yes)
5049
})
5150
})
+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//@ edition: 2024
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
6+
// Regression test for <https://github.com/rust-lang/trait-system-refactor-initiative/issues/177>.
7+
// Coroutines erase all free lifetimes from their interior types, replacing them with higher-
8+
// ranked regions which act as universals, to properly represent the fact that we don't know what
9+
// the value of the region is within the coroutine.
10+
//
11+
// In the future in `from_request`, that means that the `'r` lifetime is being replaced in
12+
// `<T as FromRequest<'r>>::Assoc`, which is in present in the existential bounds of the
13+
// `dyn Future` that it's awaiting. Normalizing this associated type, with its free lifetimes
14+
// replaced, means proving `T: FromRequest<'!0>`, which doesn't hold without constraining the
15+
// `'!0` lifetime, which we don't do today.
16+
17+
// Proving `T: Trait` holds when `<T as Trait>::Assoc` is rigid is not necessary for soundness,
18+
// at least not *yet*, and it's not even necessary for diagnostics since we have other special
19+
// casing for, e.g., AliasRelate goals failing in the BestObligation folder.
20+
21+
// The old solver unintentioanlly avoids this by never checking that `T: Trait` holds when
22+
// `<T as Trait>::Assoc` is rigid. Introducing this additional requirement when projecting rigidly
23+
// in the old solver causes this (and tons of production crates) to fail. See the fallout from the
24+
// crater run at <https://github.com/rust-lang/rust/pull/139763>.
25+
26+
use std::future::Future;
27+
use std::pin::Pin;
28+
29+
pub trait FromRequest<'r> {
30+
type Assoc;
31+
fn from_request() -> Pin<Box<dyn Future<Output = Self::Assoc> + Send>>;
32+
}
33+
34+
fn test<'r, T: FromRequest<'r>>() -> Pin<Box<dyn Future<Output = ()> + Send>> {
35+
Box::pin(async move {
36+
T::from_request().await;
37+
})
38+
}
39+
40+
fn main() {}

0 commit comments

Comments
 (0)
Please sign in to comment.