Skip to content

Commit 94bf4b5

Browse files
Don't require rigid alias's trait to hold
1 parent 990039e commit 94bf4b5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-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
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//@ compile-flags: -Znext-solver
2+
//@ edition: 2024
3+
//@ check-pass
4+
5+
// Regression test for <https://github.com/rust-lang/trait-system-refactor-initiative/issues/177>.
6+
// Coroutines erase all free lifetimes from their interior types. In the future in `from_request`,
7+
// that means the `'r` lifetime in the type `<T as FromRequest<'r>>::Assoc`, which is in the
8+
// `dyn Future` type it's awaiting. Normalizing this associated type, with its free lifetimes
9+
// replaced, means proving `T: FromRequest<'!0>`, which definitely doesn't hold.
10+
11+
// proving `T: Trait` holds when `<T as Trait>::Assoc` is rigid is not necessary for soundness,
12+
// at least not *yet*, and it's not even necessary for diagnostics since we have other special
13+
// casing for, e.g., AliasRelate goals failing in the BestObligation folder.
14+
15+
// The old solver deals this by not checking that `T: Trait` holds when `<T as Trait>::Assoc` is
16+
// rigid. Introducing this additional requirement when projecting rigidly in the old solver
17+
// causes this (and tons of production crates) to fail. See the fallout from the crater run at:
18+
// <https://github.com/rust-lang/rust/pull/139763>.
19+
20+
use std::{future::Future, pin::Pin};
21+
22+
pub trait FromRequest<'r> {
23+
type Assoc;
24+
fn from_request() -> Pin<Box<dyn Future<Output = Self::Assoc> + Send>>;
25+
}
26+
27+
fn test<'r, T: FromRequest<'r>>() -> Pin<Box<dyn Future<Output = ()> + Send>> {
28+
Box::pin(async move {
29+
T::from_request().await;
30+
})
31+
}
32+
33+
fn main() {}

0 commit comments

Comments
 (0)