diff --git a/compiler/rustc_trait_selection/src/traits/normalize.rs b/compiler/rustc_trait_selection/src/traits/normalize.rs index 71e9914f93fa8..24854990fe716 100644 --- a/compiler/rustc_trait_selection/src/traits/normalize.rs +++ b/compiler/rustc_trait_selection/src/traits/normalize.rs @@ -433,7 +433,12 @@ impl<'a, 'b, 'tcx> TypeFolder> for AssocTypeNormalizer<'a, 'b, 'tcx #[instrument(skip(self), level = "debug")] fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> { let tcx = self.selcx.tcx(); - if tcx.features().generic_const_exprs() || !needs_normalization(self.selcx.infcx, &ct) { + + if tcx.features().generic_const_exprs() + // Normalize type_const items even with feature `generic_const_exprs`. + && !matches!(ct.kind(), ty::ConstKind::Unevaluated(uv) if tcx.is_type_const(uv.def)) + || !needs_normalization(self.selcx.infcx, &ct) + { return ct; } diff --git a/tests/crashes/138089.rs b/tests/crashes/138089.rs index 054d1b2169590..f4864971ae5d1 100644 --- a/tests/crashes/138089.rs +++ b/tests/crashes/138089.rs @@ -1,4 +1,6 @@ //@ known-bug: #138089 +//@ needs-rustc-debug-assertions + #![feature(generic_const_exprs)] #![feature(min_generic_const_args)] #![feature(inherent_associated_types)] diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs new file mode 100644 index 0000000000000..823a6d58bf471 --- /dev/null +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.rs @@ -0,0 +1,11 @@ +//@ needs-rustc-debug-assertions + +#![feature(min_generic_const_args)] +#![feature(generic_const_exprs)] +#![expect(incomplete_features)] + +#[type_const] +const A: u8 = A; +//~^ ERROR overflow normalizing the unevaluated constant `A` + +fn main() {} diff --git a/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr new file mode 100644 index 0000000000000..1ce2af817277e --- /dev/null +++ b/tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr @@ -0,0 +1,11 @@ +error[E0275]: overflow normalizing the unevaluated constant `A` + --> $DIR/cyclic-type-const-151251.rs:8:1 + | +LL | const A: u8 = A; + | ^^^^^^^^^^^ + | + = note: in case this is a recursive type alias, consider using a struct, enum, or union instead + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0275`.