Rollup merge of #129208 - veluca93:adt_const_fix, r=BoxyUwU

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.

Tracking issue: https://github.com/rust-lang/rust/issues/95174

r? BoxyUwU
This commit is contained in:
Trevor Gross 2024-08-18 23:41:49 -05:00 committed by GitHub
commit 8a513f1720
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 4 deletions

View File

@ -333,14 +333,14 @@ impl<'cx, 'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for QueryNormalizer<'cx, 'tcx>
return Ok(constant);
}
let constant = constant.try_super_fold_with(self)?;
debug!(?constant, ?self.param_env);
Ok(crate::traits::with_replaced_escaping_bound_vars(
let constant = crate::traits::with_replaced_escaping_bound_vars(
self.infcx,
&mut self.universes,
constant,
|constant| constant.normalize(self.infcx.tcx, self.param_env),
))
);
debug!(?constant, ?self.param_env);
constant.try_super_fold_with(self)
}
#[inline]

View File

@ -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<const CURRENT: usize, const REMAINING: Matrix> {
_p: (),
}
impl Walk<0, BRIDGE_MATRIX> {
pub const fn new() -> Self {
Self { _p: () }
}
}