]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir/src/transform/inline.rs
inliner: Copy unevaluated constants only after successful inlining
[rust.git] / compiler / rustc_mir / src / transform / inline.rs
index 5407226e386cbd3b3821b50c3a5237c6d5653a19..4de93739992542dd838e308c40627d073953bd9d 100644 (file)
@@ -140,14 +140,6 @@ fn run_pass(&self, caller_body: &mut Body<'tcx>) {
                 continue;
             };
 
-            // Copy only unevaluated constants from the callee_body into the caller_body.
-            // Although we are only pushing `ConstKind::Unevaluated` consts to
-            // `required_consts`, here we may not only have `ConstKind::Unevaluated`
-            // because we are calling `subst_and_normalize_erasing_regions`.
-            caller_body.required_consts.extend(callee_body.required_consts.iter().copied().filter(
-                |&constant| matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _)),
-            ));
-
             let start = caller_body.basic_blocks().len();
             debug!("attempting to inline callsite {:?} - body={:?}", callsite, callee_body);
             if !self.inline_call(callsite, caller_body, callee_body) {
@@ -522,6 +514,16 @@ fn dest_needs_borrow(place: Place<'_>) -> bool {
                     kind: TerminatorKind::Goto { target: integrator.map_block(START_BLOCK) },
                 });
 
+                // Copy only unevaluated constants from the callee_body into the caller_body.
+                // Although we are only pushing `ConstKind::Unevaluated` consts to
+                // `required_consts`, here we may not only have `ConstKind::Unevaluated`
+                // because we are calling `subst_and_normalize_erasing_regions`.
+                caller_body.required_consts.extend(
+                    callee_body.required_consts.iter().copied().filter(|&constant| {
+                        matches!(constant.literal.val, ConstKind::Unevaluated(_, _, _))
+                    }),
+                );
+
                 true
             }
             kind => {