Skip to content

Commit ea443af

Browse files
committed
fix ice nested array
1 parent 7c4dcca commit ea443af

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

compiler/rustc_mir_transform/src/promote_consts_local_arrays.rs

+3
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ impl<'a, 'tcx> std::ops::Deref for Validator<'a, 'tcx> {
252252
struct Unpromotable;
253253

254254
impl<'tcx> Validator<'_, 'tcx> {
255+
#[instrument(level = "trace", skip(self))]
255256
fn validate_candidate(&mut self, candidate: Location) -> Result<(), Unpromotable> {
256257
let Left(statement) = self.body.stmt_at(candidate) else { bug!() };
257258
let Some((place, rvalue @ Rvalue::Aggregate(box kind, operands))) =
@@ -276,6 +277,8 @@ impl<'tcx> Validator<'_, 'tcx> {
276277
&& size.bytes() <= STACK_THRESHOLD
277278
{
278279
debug!("size of array is too small: {:?}", size);
280+
// for nested arrays
281+
self.temps[place.local] = TempState::Unpromotable;
279282
return Err(Unpromotable);
280283
}
281284

tests/mir-opt/const_array_locals.rs

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub fn main() {
3434
159, 22, 157, 105, 31, 96, 173, 50, 1,]);
3535

3636
let _f = F32x8([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]);
37+
38+
// ice
39+
[[1, 0, 0], [0, 1, 0], [0, 0, 1]]; // 2D array
3740
}
3841

3942
fn consume(_arr: [u16; 32]) {

0 commit comments

Comments
 (0)