diff --git a/compiler/rustc_trait_selection/src/traits/query/normalize.rs b/compiler/rustc_trait_selection/src/traits/query/normalize.rs index 02438b24ca7f4..2f83ee046498a 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 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> { // `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 0000000000000..72a3098b76cfe --- /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: usize = { ::N }; + +trait Trait { + type const N: usize; +} + +impl Trait for T { + type const N:usize = 0; +} + +fn f(_x: [(); CT::<()>]) {} + +fn main() {}