Skip to content

Commit

Permalink
Rollup merge of #75502 - ecstatic-morse:implicit-promotion-in-const-f…
Browse files Browse the repository at this point in the history
…n, 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
  • Loading branch information
RalfJung committed Sep 19, 2020
2 parents aa25f9e + e03f416 commit f62ba52
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion compiler/rustc_mir/src/transform/promote_consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]`.
Expand Down

0 comments on commit f62ba52

Please sign in to comment.