diff options
| author | Dylan DPC <dylan.dpc@gmail.com> | 2020-09-05 16:28:30 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-09-05 16:28:30 +0200 |
| commit | 79b8f59185c09b862757553a037c5f0282d20eed (patch) | |
| tree | 2bd3ac9dbc199c2ce40a41687658b76cb744cffe | |
| parent | f1eb5f800fddbea8876930cdeffa55545e17f447 (diff) | |
| parent | af19262ab447b358ae6da516751fd9ad79695996 (diff) | |
| download | rust-79b8f59185c09b862757553a037c5f0282d20eed.tar.gz rust-79b8f59185c09b862757553a037c5f0282d20eed.zip | |
Rollup merge of #76254 - tmiasko:fold-len, r=wesleywiser
Fold length constant in Rvalue::Repeat Fixes #76248.
| -rw-r--r-- | compiler/rustc_middle/src/mir/type_foldable.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/mir/issue-76248.rs | 29 |
2 files changed, 30 insertions, 1 deletions
diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index 6bb6abe0289..ad2eae0298c 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -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)) diff --git a/src/test/ui/mir/issue-76248.rs b/src/test/ui/mir/issue-76248.rs new file mode 100644 index 00000000000..b01a9727852 --- /dev/null +++ b/src/test/ui/mir/issue-76248.rs @@ -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(); +} |
