Skip to content

Fold length constant in Rvalue::Repeat #76254

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}