about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan MacKenzie <ecstaticmorse@gmail.com>2019-10-29 08:24:59 -0700
committerDylan MacKenzie <ecstaticmorse@gmail.com>2019-10-29 13:58:17 -0700
commit9bb983380b3ebb61e8b6333f7af61b3c04c062da (patch)
tree22480f45c8761d45cda1adf111d53c96911a86db
parent8d78bf6b273848d17da8f5c92162c6a6b9b10dfd (diff)
downloadrust-9bb983380b3ebb61e8b6333f7af61b3c04c062da.tar.gz
rust-9bb983380b3ebb61e8b6333f7af61b3c04c062da.zip
Add method to `Candidate` that determines its promotability rules
-rw-r--r--src/librustc_mir/transform/promote_consts.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs
index 3af08090853..ced5c0146d9 100644
--- a/src/librustc_mir/transform/promote_consts.rs
+++ b/src/librustc_mir/transform/promote_consts.rs
@@ -80,6 +80,17 @@ pub enum Candidate {
     Argument { bb: BasicBlock, index: usize },
 }
 
+impl Candidate {
+    /// Returns `true` if we should use the "explicit" rules for promotability for this `Candidate`.
+    fn forces_explicit_promotion(&self) -> bool {
+        match self {
+            Candidate::Ref(_) |
+            Candidate::Repeat(_) => false,
+            Candidate::Argument { .. } => true,
+        }
+    }
+}
+
 fn args_required_const(tcx: TyCtxt<'_>, def_id: DefId) -> Option<Vec<usize>> {
     let attrs = tcx.get_attrs(def_id);
     let attr = attrs.iter().find(|a| a.check_name(sym::rustc_args_required_const))?;
@@ -727,11 +738,7 @@ pub fn validate_candidates(
     };
 
     candidates.iter().copied().filter(|&candidate| {
-        validator.explicit = match candidate {
-            Candidate::Ref(_) |
-            Candidate::Repeat(_) => false,
-            Candidate::Argument { .. } => true,
-        };
+        validator.explicit = candidate.forces_explicit_promotion();
 
         // FIXME(eddyb) also emit the errors for shuffle indices
         // and `#[rustc_args_required_const]` arguments here.