From 7fd62320feddcb3fa85a3ab25bc4c0ac55ddac7c Mon Sep 17 00:00:00 2001 From: Luca Versari Date: Sat, 17 Aug 2024 20:45:45 +0200 Subject: Fix order of normalization and recursion in const folding. Fixes #126831. Without this patch, type normalization is not always idempotent, which leads to all sorts of bugs in places that assume that normalizing a normalized type does nothing. --- tests/ui/const-generics/const-ty-is-normalized.rs | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 tests/ui/const-generics/const-ty-is-normalized.rs (limited to 'tests') diff --git a/tests/ui/const-generics/const-ty-is-normalized.rs b/tests/ui/const-generics/const-ty-is-normalized.rs new file mode 100644 index 00000000000..784145f735e --- /dev/null +++ b/tests/ui/const-generics/const-ty-is-normalized.rs @@ -0,0 +1,25 @@ +//@ compile-flags: -Cdebuginfo=2 --crate-type=lib +//@ build-pass +#![feature(adt_const_params)] + +const N_ISLANDS: usize = 4; + +pub type Matrix = [[usize; N_ISLANDS]; N_ISLANDS]; + +const EMPTY_MATRIX: Matrix = [[0; N_ISLANDS]; N_ISLANDS]; + +const fn to_matrix() -> Matrix { + EMPTY_MATRIX +} + +const BRIDGE_MATRIX: [[usize; N_ISLANDS]; N_ISLANDS] = to_matrix(); + +pub struct Walk { + _p: (), +} + +impl Walk<0, BRIDGE_MATRIX> { + pub const fn new() -> Self { + Self { _p: () } + } +} -- cgit 1.4.1-3-g733a5