Skip to content

Commit f62ba52

Browse files
authored
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 rust-lang/const-eval#54 (comment). cc #75586
2 parents aa25f9e + e03f416 commit f62ba52

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

compiler/rustc_mir/src/transform/promote_consts.rs

+8-1
Original file line numberDiff line numberDiff line change
@@ -734,7 +734,14 @@ impl<'tcx> Validator<'_, 'tcx> {
734734
) -> Result<(), Unpromotable> {
735735
let fn_ty = callee.ty(self.body, self.tcx);
736736

737-
if !self.explicit && self.const_kind.is_none() {
737+
// `const` and `static` use the explicit rules for promotion regardless of the `Candidate`,
738+
// meaning calls to `const fn` can be promoted.
739+
let context_uses_explicit_promotion_rules = matches!(
740+
self.const_kind,
741+
Some(hir::ConstContext::Static(_) | hir::ConstContext::Const)
742+
);
743+
744+
if !self.explicit && !context_uses_explicit_promotion_rules {
738745
if let ty::FnDef(def_id, _) = *fn_ty.kind() {
739746
// Never promote runtime `const fn` calls of
740747
// functions without `#[rustc_promotable]`.

0 commit comments

Comments
 (0)