]> git.lizzy.rs Git - rust.git/commitdiff
Promote `Repeat`s to constants instead of statics
authorSantiago Pastorino <spastorino@gmail.com>
Tue, 10 Dec 2019 23:40:29 +0000 (20:40 -0300)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Fri, 10 Jan 2020 08:08:24 +0000 (09:08 +0100)
src/librustc_mir/transform/promote_consts.rs

index f8851f7dbdcf053a1151b6ba8a94d1dd3aea4289..e160e922f4c44b58e8e839c203aadacb97dca8a5 100644 (file)
@@ -1002,10 +1002,25 @@ fn promote_candidate(
                         StatementKind::Assign(box (_, Rvalue::Repeat(ref mut operand, _))) => {
                             let ty = operand.ty(local_decls, self.tcx);
                             let span = statement.source_info.span;
-                            Rvalue::Use(mem::replace(
-                                operand,
-                                Operand::Copy(promoted_place(ty, span)),
-                            ))
+
+                            promoted.span = span;
+                            promoted.local_decls[RETURN_PLACE] =
+                                LocalDecl::new_return_place(ty, span);
+
+                            let promoted_operand = Operand::Constant(Box::new(Constant {
+                                span,
+                                user_ty: None,
+                                literal: tcx.mk_const(ty::Const {
+                                    ty,
+                                    val: ty::ConstKind::Unevaluated(
+                                        def_id,
+                                        InternalSubsts::identity_for_item(tcx, def_id),
+                                        Some(promoted_id),
+                                    ),
+                                }),
+                            }));
+
+                            Rvalue::Use(mem::replace(operand, promoted_operand))
                         }
                         _ => bug!(),
                     }