about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2019-10-29 12:50:43 -0700
committerDylan MacKenzie <ecstaticmorse@gmail.com>2019-10-29 13:58:17 -0700
commit46b68b009ba64330f6ad503a1882a7df637b1a86 (patch)
treed90afd80fc0802e877bf1930b34e04292ba3b102
parent9bb983380b3ebb61e8b6333f7af61b3c04c062da (diff)
Emit errors in `promote_consts` when required promotion fails
-rw-r--r--src/librustc_mir/transform/promote_consts.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs
index ced5c0146d9..9bd9aba945e 100644
--- a/src/librustc_mir/transform/promote_consts.rs
+++ b/src/librustc_mir/transform/promote_consts.rs
@@ -743,7 +743,17 @@ pub fn validate_candidates(
         // FIXME(eddyb) also emit the errors for shuffle indices
         // and `#[rustc_args_required_const]` arguments here.
 
-        validator.validate_candidate(candidate).is_ok()
+        let is_promotable = validator.validate_candidate(candidate).is_ok();
+        match candidate {
+            Candidate::Argument { bb, index } if !is_promotable => {
+                let span = body[bb].terminator().source_info.span;
+                let msg = format!("argument {} is required to be a constant", index + 1);
+                tcx.sess.span_err(span, &msg);
+            }
+            _ => ()
+        }
+
+        is_promotable
     }).collect()
 }