Skip to content

Commit 92e9023

Browse files
authored
Rollup merge of rust-lang#122319 - compiler-errors:next-solver-normalizing-self-constrains-args, r=lcnr
Don't ICE when non-self part of trait goal is constrained in new solver Self-explanatory. See test for example when this can happen.
2 parents 7a27bd3 + 0b6b330 commit 92e9023

19 files changed

+38
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,9 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
274274

275275
let goal =
276276
goal.with(self.tcx(), goal.predicate.with_self_ty(self.tcx(), normalized_self_ty));
277-
debug_assert_eq!(goal, self.resolve_vars_if_possible(goal));
277+
// Vars that show up in the rest of the goal substs may have been constrained by
278+
// normalizing the self type as well, since type variables are not uniquified.
279+
let goal = self.resolve_vars_if_possible(goal);
278280

279281
let mut candidates = vec![];
280282

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//@ check-pass
2+
3+
// This goal is also possible w/ a GAT, but lazy_type_alias
4+
// makes the behavior a bit more readable.
5+
#![feature(lazy_type_alias)]
6+
//~^ WARN the feature `lazy_type_alias` is incomplete
7+
8+
struct Wr<T>(T);
9+
trait Foo {}
10+
impl Foo for Wr<i32> {}
11+
12+
type Alias<T> = (T,)
13+
where Wr<T>: Foo;
14+
15+
fn hello<T>() where Alias<T>: Into<(T,)>, Wr<T>: Foo {}
16+
17+
fn main() {
18+
// When calling `hello`, proving `Alias<?0>: Into<(?0,)>` will require
19+
// normalizing the self type of the goal. This will emit the where
20+
// clause `Wr<?0>: Foo`, which constrains `?0` in both the self type
21+
// *and* the non-self part of the goal. That used to trigger a debug
22+
// assertion.
23+
hello::<_>();
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes
2+
--> $DIR/normalize-self-type-constrains-trait-args.rs:5:12
3+
|
4+
LL | #![feature(lazy_type_alias)]
5+
| ^^^^^^^^^^^^^^^
6+
|
7+
= note: see issue #112792 <https://github.com/rust-lang/rust/issues/112792> for more information
8+
= note: `#[warn(incomplete_features)]` on by default
9+
10+
warning: 1 warning emitted
11+

0 commit comments

Comments
 (0)