Skip to content

Commit 7510f74

Browse files
committed
Normalize type_const items even with feature generic_const_exprs
1 parent 9f6cd6d commit 7510f74

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

compiler/rustc_trait_selection/src/traits/normalize.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,12 @@ impl<'a, 'b, 'tcx> TypeFolder<TyCtxt<'tcx>> for AssocTypeNormalizer<'a, 'b, 'tcx
433433
#[instrument(skip(self), level = "debug")]
434434
fn fold_const(&mut self, ct: ty::Const<'tcx>) -> ty::Const<'tcx> {
435435
let tcx = self.selcx.tcx();
436-
if tcx.features().generic_const_exprs() || !needs_normalization(self.selcx.infcx, &ct) {
436+
437+
if tcx.features().generic_const_exprs()
438+
// Normalize type_const items even with feature `generic_const_exprs`.
439+
&& !matches!(ct.kind(), ty::ConstKind::Unevaluated(uv) if tcx.is_type_const(uv.def))
440+
|| !needs_normalization(self.selcx.infcx, &ct)
441+
{
437442
return ct;
438443
}
439444

tests/crashes/138089.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
//@ known-bug: #138089
2+
//@ needs-rustc-debug-assertions
3+
24
#![feature(generic_const_exprs)]
35
#![feature(min_generic_const_args)]
46
#![feature(inherent_associated_types)]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ needs-rustc-debug-assertions
2+
3+
#![feature(min_generic_const_args)]
4+
#![feature(generic_const_exprs)]
5+
#![expect(incomplete_features)]
6+
7+
#[type_const]
8+
const A: u8 = A;
9+
//~^ ERROR overflow normalizing the unevaluated constant `A`
10+
11+
fn main() {}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0275]: overflow normalizing the unevaluated constant `A`
2+
--> $DIR/cyclic-type-const-151251.rs:8:1
3+
|
4+
LL | const A: u8 = A;
5+
| ^^^^^^^^^^^
6+
|
7+
= note: in case this is a recursive type alias, consider using a struct, enum, or union instead
8+
9+
error: aborting due to 1 previous error
10+
11+
For more information about this error, try `rustc --explain E0275`.

0 commit comments

Comments
 (0)