Skip to content

Commit

Permalink
Fold length constant in Rvalue::Repeat
Browse files Browse the repository at this point in the history
  • Loading branch information
tmiasko committed Sep 2, 2020
1 parent da897df commit af19262
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/mir/type_foldable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> {
use crate::mir::Rvalue::*;
match *self {
Use(ref op) => Use(op.fold_with(folder)),
Repeat(ref op, len) => Repeat(op.fold_with(folder), len),
Repeat(ref op, len) => Repeat(op.fold_with(folder), len.fold_with(folder)),
ThreadLocalRef(did) => ThreadLocalRef(did.fold_with(folder)),
Ref(region, bk, ref place) => {
Ref(region.fold_with(folder), bk, place.fold_with(folder))
Expand Down
29 changes: 29 additions & 0 deletions src/test/ui/mir/issue-76248.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This used to ICE during codegen after MIR inlining of g into f.
// The root cause was a missing fold of length constant in Rvalue::Repeat.
// Regression test for #76248.
//
// build-pass
// compile-flags: -Zmir-opt-level=2

const N: usize = 1;

pub struct Elem<M> {
pub x: [usize; N],
pub m: M,
}

pub fn f() -> Elem<()> {
g(())
}

#[inline]
pub fn g<M>(m: M) -> Elem<M> {
Elem {
x: [0; N],
m,
}
}

pub fn main() {
f();
}

0 comments on commit af19262

Please sign in to comment.