]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #66066 - ecstatic-morse:remove-promotion-from-qualify-consts, r=eddyb
authorbors <bors@rust-lang.org>
Fri, 8 Nov 2019 07:55:53 +0000 (07:55 +0000)
committerbors <bors@rust-lang.org>
Fri, 8 Nov 2019 07:55:53 +0000 (07:55 +0000)
Remove promotion candidate gathering and checking from `qualify_consts.rs`

This makes promotion candidate gathering and checking the exclusive domain of `promote_consts`, but the `QualifyAndPromoteConsts` pass is still responsible for both const-checking and creating promoted MIR fragments.

This should not be merged until the beta branches on Nov. 5.

r? @eddyb

1  2 
src/librustc_mir/transform/qualify_consts.rs

index 3de9998653d0a6702d9cd5a5262eac13b3b1ffe1,600d4735370abfdb1a8318fbc211ca51ca4b6257..6a7058f19301782b4ce58d7d94a59c8b01456053
@@@ -1047,26 -775,26 +775,27 @@@ impl<'a, 'tcx> Checker<'a, 'tcx> 
          // Collect all the temps we need to promote.
          let mut promoted_temps = BitSet::new_empty(self.temp_promotion_state.len());
  
-         // HACK(eddyb) don't try to validate promotion candidates if any
-         // parts of the control-flow graph were skipped due to an error.
-         let promotion_candidates = if has_controlflow_error {
-             let unleash_miri = self
-                 .tcx
-                 .sess
-                 .opts
-                 .debugging_opts
-                 .unleash_the_miri_inside_of_you;
-             if !unleash_miri {
-                 self.tcx.sess.delay_span_bug(
-                     body.span,
-                     "check_const: expected control-flow error(s)",
-                 );
-             }
-             self.promotion_candidates.clone()
+         // HACK: if parts of the control-flow graph were skipped due to an error, don't try to
+         // promote anything, since that can cause errors in a `const` if e.g. rvalue static
+         // promotion is attempted within a loop body.
+         let unleash_miri = self.tcx.sess.opts.debugging_opts.unleash_the_miri_inside_of_you;
+         let promotion_candidates = if has_controlflow_error && !unleash_miri {
+             self.tcx.sess.delay_span_bug(
+                 body.span,
+                 "check_const: expected control-flow error(s)",
+             );
+             vec![]
          } else {
-             self.valid_promotion_candidates()
+             promote_consts::validate_candidates(
+                 self.tcx,
+                 self.body,
+                 self.def_id,
+                 &self.temp_promotion_state,
+                 &self.unchecked_promotion_candidates,
+             )
          };
 +
          debug!("qualify_const: promotion_candidates={:?}", promotion_candidates);
          for candidate in promotion_candidates {
              match candidate {