Skip to content

Commit 55f56f2

Browse files
committed
Fix const normalization for generic const items with trait assoc consts
1 parent ce0bf0b commit 55f56f2

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

compiler/rustc_trait_selection/src/traits/query/normalize.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,14 @@ impl<'a, 'tcx> QueryNormalizer<'a, 'tcx> {
376376
// `tcx.normalize_canonicalized_projection` may normalize to a type that
377377
// still has unevaluated consts, so keep normalizing here if that's the case.
378378
// Similarly, `tcx.normalize_canonicalized_free_alias` will only unwrap one layer
379-
// of type and we need to continue folding it to reveal the TAIT behind it.
379+
// of type/const and we need to continue folding it to reveal the TAIT behind it
380+
// or further normalize nested unevaluated consts.
380381
if res != term.to_term(tcx)
381-
&& (res.as_type().map_or(false, |t| t.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION))
382-
|| term.kind(tcx) == ty::AliasTermKind::FreeTy)
382+
&& (res.has_type_flags(ty::TypeFlags::HAS_CT_PROJECTION)
383+
|| matches!(
384+
term.kind(tcx),
385+
ty::AliasTermKind::FreeTy | ty::AliasTermKind::FreeConst
386+
))
383387
{
384388
res.try_fold_with(self)
385389
} else {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//@ check-pass
2+
3+
#![feature(generic_const_items, min_generic_const_args)]
4+
#![allow(incomplete_features)]
5+
6+
type const CT<T: ?Sized>: usize = { <T as Trait>::N };
7+
8+
trait Trait {
9+
type const N: usize;
10+
}
11+
12+
impl<T: ?Sized> Trait for T {
13+
type const N = 0;
14+
}
15+
16+
fn f(_x: [(); CT::<()>]) {}
17+
18+
fn main() {}

0 commit comments

Comments
 (0)