Skip to content

Commit af19262

Browse files
committed
Fold length constant in Rvalue::Repeat
1 parent da897df commit af19262

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

compiler/rustc_middle/src/mir/type_foldable.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
175175
use crate::mir::Rvalue::*;
176176
match *self {
177177
Use(ref op) => Use(op.fold_with(folder)),
178-
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
178+
Repeat(ref op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)),
179179
ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)),
180180
Ref(region, bk, ref place) => {
181181
Ref(region.fold_with(folder), bk, place.fold_with(folder))

src/test/ui/mir/issue-76248.rs

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// This used to ICE during codegen after MIR inlining of g into f.
2+
// The root cause was a missing fold of length constant in Rvalue::Repeat.
3+
// Regression test for #76248.
4+
//
5+
// build-pass
6+
// compile-flags: -Zmir-opt-level=2
7+
8+
const N: usize = 1;
9+
10+
pub struct Elem<M> {
11+
pub x: [usize; N],
12+
pub m: M,
13+
}
14+
15+
pub fn f() -> Elem<()> {
16+
g(())
17+
}
18+
19+
#[inline]
20+
pub fn g<M>(m: M) -> Elem<M> {
21+
Elem {
22+
x: [0; N],
23+
m,
24+
}
25+
}
26+
27+
pub fn main() {
28+
f();
29+
}

0 commit comments

Comments
 (0)