Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion compiler/rustc_trait_selection/src/traits/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> 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;
}

Expand Down
2 changes: 2 additions & 0 deletions tests/crashes/138089.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
//@ known-bug: #138089
//@ needs-rustc-debug-assertions

#![feature(generic_const_exprs)]
#![feature(min_generic_const_args)]
#![feature(inherent_associated_types)]
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/const-generics/mgca/cyclic-type-const-151251.rs
Original file line number Diff line number Diff line change
@@ -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() {}
11 changes: 11 additions & 0 deletions tests/ui/const-generics/mgca/cyclic-type-const-151251.stderr
Original file line number Diff line number Diff line change
@@ -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`.
Loading