about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-09-19 11:47:35 +0200
committerGitHub <noreply@github.com>2020-09-19 11:47:35 +0200
commitf62ba52f5c100eadd658d6685e680518b71cdb77 (patch)
tree03c9e2c303489d35ce2d7041e0c1d54a83c42d9e
parentaa25f9ebd8ca5cb4751f796b8b9b4d9909d8d340 (diff)
parente03f4164d9229d8a79ab2d9c20221d0b646734ae (diff)
downloadrust-f62ba52f5c100eadd658d6685e680518b71cdb77.tar.gz
rust-f62ba52f5c100eadd658d6685e680518b71cdb77.zip
Rollup merge of #75502 - ecstatic-morse:implicit-promotion-in-const-fn, r=RalfJung
Use implicit (not explicit) rules for promotability by default in `const fn`

For crater run. See https://github.com/rust-lang/const-eval/pull/54#discussion_r469995552.

cc #75586
-rw-r--r--compiler/rustc_mir/src/transform/promote_consts.rs9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/rustc_mir/src/transform/promote_consts.rs b/compiler/rustc_mir/src/transform/promote_consts.rs
index 1d2295a37dd..b6124049579 100644
--- a/compiler/rustc_mir/src/transform/promote_consts.rs
+++ b/compiler/rustc_mir/src/transform/promote_consts.rs
@@ -734,7 +734,14 @@ impl<'tcx> Validator<'_, 'tcx> {
     ) -> Result<(), Unpromotable> {
         let fn_ty = callee.ty(self.body, self.tcx);
 
-        if !self.explicit && self.const_kind.is_none() {
+        // `const` and `static` use the explicit rules for promotion regardless of the `Candidate`,
+        // meaning calls to `const fn` can be promoted.
+        let context_uses_explicit_promotion_rules = matches!(
+            self.const_kind,
+            Some(hir::ConstContext::Static(_) | hir::ConstContext::Const)
+        );
+
+        if !self.explicit && !context_uses_explicit_promotion_rules {
             if let ty::FnDef(def_id, _) = *fn_ty.kind() {
                 // Never promote runtime `const fn` calls of
                 // functions without `#[rustc_promotable]`.