diff --git a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs index 3be53a6591d..9c7fa5216d7 100644 --- a/compiler/rustc_trait_selection/src/solve/assembly/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/assembly/mod.rs @@ -274,7 +274,9 @@ pub(super) fn assemble_and_evaluate_candidates>( let goal = goal.with(self.tcx(), goal.predicate.with_self_ty(self.tcx(), normalized_self_ty)); - debug_assert_eq!(goal, self.resolve_vars_if_possible(goal)); + // Vars that show up in the rest of the goal substs may have been constrained by + // normalizing the self type as well, since type variables are not uniquified. + let goal = self.resolve_vars_if_possible(goal); let mut candidates = vec![]; diff --git a/tests/ui/traits/next-solver/normalize-self-type-constrains-trait-args.rs b/tests/ui/traits/next-solver/normalize-self-type-constrains-trait-args.rs new file mode 100644 index 00000000000..0ece8f8321c --- /dev/null +++ b/tests/ui/traits/next-solver/normalize-self-type-constrains-trait-args.rs @@ -0,0 +1,24 @@ +//@ check-pass + +// This goal is also possible w/ a GAT, but lazy_type_alias +// makes the behavior a bit more readable. +#![feature(lazy_type_alias)] +//~^ WARN the feature `lazy_type_alias` is incomplete + +struct Wr(T); +trait Foo {} +impl Foo for Wr {} + +type Alias = (T,) + where Wr: Foo; + +fn hello() where Alias: Into<(T,)>, Wr: Foo {} + +fn main() { + // When calling `hello`, proving `Alias: Into<(?0,)>` will require + // normalizing the self type of the goal. This will emit the where + // clause `Wr: Foo`, which constrains `?0` in both the self type + // *and* the non-self part of the goal. That used to trigger a debug + // assertion. + hello::<_>(); +} diff --git a/tests/ui/traits/next-solver/normalize-self-type-constrains-trait-args.stderr b/tests/ui/traits/next-solver/normalize-self-type-constrains-trait-args.stderr new file mode 100644 index 00000000000..5554f0ccc0a --- /dev/null +++ b/tests/ui/traits/next-solver/normalize-self-type-constrains-trait-args.stderr @@ -0,0 +1,11 @@ +warning: the feature `lazy_type_alias` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/normalize-self-type-constrains-trait-args.rs:5:12 + | +LL | #![feature(lazy_type_alias)] + | ^^^^^^^^^^^^^^^ + | + = note: see issue #112792 for more information + = note: `#[warn(incomplete_features)]` on by default + +warning: 1 warning emitted +