We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
const fn
1 parent 9b41541 commit e03f416Copy full SHA for e03f416
compiler/rustc_mir/src/transform/promote_consts.rs
@@ -734,7 +734,14 @@ impl<'tcx> Validator<'_, 'tcx> {
734
) -> Result<(), Unpromotable> {
735
let fn_ty = callee.ty(self.body, self.tcx);
736
737
- if !self.explicit && self.const_kind.is_none() {
+ // `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 {
745
if let ty::FnDef(def_id, _) = *fn_ty.kind() {
746
// Never promote runtime `const fn` calls of
747
// functions without `#[rustc_promotable]`.
0 commit comments