Fix const normalization for generic const items with trait assoc consts
diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 02438b2..2f83ee0 100644 --- a/compiler/rustc_trait_selection/src/traits/query/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/query/normalize.rs
@@ -376,10 +376,14 @@ fn try_fold_free_or_assoc( // `tcx.normalize_canonicalized_projection` may normalize to a type that // still has unevaluated consts, so keep normalizing here if that's the case. // Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer - // of type and we need to continue folding it to reveal the TAIT behind it. + // of type/const and we need to continue folding it to reveal the TAIT behind it + // or further normalize nested unevaluated consts. if res != term.to_term(tcx) - && (res.as_type().map_or(false, |t| t.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)) - || term.kind(tcx) == ty::AliasTermKind::FreeTy) + && (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION) + || matches!( + term.kind(tcx), + ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst + )) { res.try_fold_with(self) } else {
diff --git a/tests/ui/generic-const-items/type-const-nested-assoc-const.rs b/tests/ui/generic-const-items/type-const-nested-assoc-const.rs new file mode 100644 index 0000000..72a3098 --- /dev/null +++ b/tests/ui/generic-const-items/type-const-nested-assoc-const.rs
@@ -0,0 +1,18 @@ +//@ check-pass + +#![feature(generic_const_items, min_generic_const_args)] +#![allow(incomplete_features)] + +type const CT<T: ?Sized>: usize = { <T as Trait>::N }; + +trait Trait { + type const N: usize; +} + +impl<T: ?Sized> Trait for T { + type const N:usize = 0; +} + +fn f(_x: [(); CT::<()>]) {} + +fn main() {}