Default to implicit (not explicit) rules for promotability in const fn
This commit is contained in:
parent
9b4154193e
commit
e03f4164d9
1 changed files with 8 additions and 1 deletions
|
@ -734,7 +734,14 @@ impl<'tcx> Validator<'_, 'tcx> {
|
||||||
) -> Result<(), Unpromotable> {
|
) -> Result<(), Unpromotable> {
|
||||||
let fn_ty = callee.ty(self.body, self.tcx);
|
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() {
|
if let ty::FnDef(def_id, _) = *fn_ty.kind() {
|
||||||
// Never promote runtime `const fn` calls of
|
// Never promote runtime `const fn` calls of
|
||||||
// functions without `#[rustc_promotable]`.
|
// functions without `#[rustc_promotable]`.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue