about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/librustc_mir/transform/mod.rs7
-rw-r--r--src/librustc_mir/transform/qualify_consts.rs56
-rw-r--r--src/test/mir-opt/match_false_edges.rs12
3 files changed, 27 insertions, 48 deletions
diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs
index dbe6c784592..6d6d6bea2a0 100644
--- a/src/librustc_mir/transform/mod.rs
+++ b/src/librustc_mir/transform/mod.rs
@@ -210,13 +210,14 @@ fn mir_validated(
     }
 
     let mut body = tcx.mir_const(def_id).steal();
-    let qualify_and_promote_pass = qualify_consts::QualifyAndPromoteConstants::default();
+    let promote_pass = promote_consts::PromoteTemps::default();
     run_passes(tcx, &mut body, InstanceDef::Item(def_id), None, MirPhase::Validated, &[
         // What we need to run borrowck etc.
-        &qualify_and_promote_pass,
+        &qualify_consts::QualifyAndPromoteConstants::default(),
+        &promote_pass,
         &simplify::SimplifyCfg::new("qualify-consts"),
     ]);
-    let promoted = qualify_and_promote_pass.promoted.into_inner();
+    let promoted = promote_pass.promoted_fragments.into_inner();
     (tcx.alloc_steal_mir(body), tcx.alloc_steal_promoted(promoted))
 }
 
diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs
index aebc9d23492..01111af7c3e 100644
--- a/src/librustc_mir/transform/qualify_consts.rs
+++ b/src/librustc_mir/transform/qualify_consts.rs
@@ -1345,48 +1345,27 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
         let mode = determine_mode(tcx, hir_id, def_id);
 
         debug!("run_pass: mode={:?}", mode);
-        if let Mode::NonConstFn | Mode::ConstFn = mode {
+        if let Mode::NonConstFn = mode {
+            // No need to const-check a non-const `fn` now that we don't do promotion here.
+            return;
+        } else if let Mode::ConstFn = mode {
             let mut checker = Checker::new(tcx, def_id, body, mode);
-            if let Mode::ConstFn = mode {
-                let use_min_const_fn_checks =
-                    !tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you &&
-                    tcx.is_min_const_fn(def_id);
-                if use_min_const_fn_checks {
-                    // Enforce `min_const_fn` for stable `const fn`s.
-                    use super::qualify_min_const_fn::is_min_const_fn;
-                    if let Err((span, err)) = is_min_const_fn(tcx, def_id, body) {
-                        error_min_const_fn_violation(tcx, span, err);
-                        return;
-                    }
-
-                    // `check_const` should not produce any errors, but better safe than sorry
-                    // FIXME(#53819)
-                    // NOTE(eddyb) `check_const` is actually needed for promotion inside
-                    // `min_const_fn` functions.
-                }
-
-                // Enforce a constant-like CFG for `const fn`.
-                checker.check_const();
-            } else {
-                while let Some((bb, data)) = checker.rpo.next() {
-                    checker.visit_basic_block_data(bb, data);
+            let use_min_const_fn_checks =
+                !tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you &&
+                tcx.is_min_const_fn(def_id);
+            if use_min_const_fn_checks {
+                // Enforce `min_const_fn` for stable `const fn`s.
+                use super::qualify_min_const_fn::is_min_const_fn;
+                if let Err((span, err)) = is_min_const_fn(tcx, def_id, body) {
+                    error_min_const_fn_violation(tcx, span, err);
+                    return;
                 }
             }
 
-            // Promote only the promotable candidates.
-            let temps = checker.temp_promotion_state;
-            let candidates = promote_consts::validate_candidates(
-                tcx,
-                body,
-                def_id,
-                &temps,
-                &checker.unchecked_promotion_candidates,
-            );
-
-            // Do the actual promotion, now that we know what's viable.
-            self.promoted.set(
-                promote_consts::promote_candidates(def_id, body, tcx, temps, candidates)
-            );
+            // `check_const` should not produce any errors, but better safe than sorry
+            // FIXME(#53819)
+            // Enforce a constant-like CFG for `const fn`.
+            checker.check_const();
         } else {
             check_short_circuiting_in_const_local(tcx, body, mode);
 
@@ -1394,7 +1373,6 @@ impl<'tcx> MirPass<'tcx> for QualifyAndPromoteConstants<'tcx> {
                 Mode::Const => tcx.mir_const_qualif(def_id),
                 _ => Checker::new(tcx, def_id, body, mode).check_const(),
             };
-            remove_drop_and_storage_dead_on_promoted_locals(body, unimplemented!());
         }
 
         if mode == Mode::Static && !tcx.has_attr(def_id, sym::thread_local) {
diff --git a/src/test/mir-opt/match_false_edges.rs b/src/test/mir-opt/match_false_edges.rs
index b275c06e05c..648856b5523 100644
--- a/src/test/mir-opt/match_false_edges.rs
+++ b/src/test/mir-opt/match_false_edges.rs
@@ -39,7 +39,7 @@ fn main() {
 
 // END RUST SOURCE
 //
-// START rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
+// START rustc.full_tested_match.PromoteTemps.after.mir
 //  bb0: {
 //      ...
 //      _2 = std::option::Option::<i32>::Some(const 42i32,);
@@ -108,9 +108,9 @@ fn main() {
 //      _0 = ();
 //      return;
 //  }
-// END rustc.full_tested_match.QualifyAndPromoteConstants.after.mir
+// END rustc.full_tested_match.PromoteTemps.after.mir
 //
-// START rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
+// START rustc.full_tested_match2.PromoteTemps.before.mir
 //  bb0: {
 //      ...
 //      _2 = std::option::Option::<i32>::Some(const 42i32,);
@@ -179,9 +179,9 @@ fn main() {
 //      _0 = ();
 //      return;
 //  }
-// END rustc.full_tested_match2.QualifyAndPromoteConstants.before.mir
+// END rustc.full_tested_match2.PromoteTemps.before.mir
 //
-// START rustc.main.QualifyAndPromoteConstants.before.mir
+// START rustc.main.PromoteTemps.before.mir
 //  bb0: {
 //     ...
 //      _2 = std::option::Option::<i32>::Some(const 1i32,);
@@ -276,4 +276,4 @@ fn main() {
 //      _0 = ();
 //      return;
 //  }
-// END rustc.main.QualifyAndPromoteConstants.before.mir
+// END rustc.main.PromoteTemps.before.mir