]> git.lizzy.rs Git - rust.git/blobdiff - compiler/rustc_mir/src/const_eval/machine.rs
Auto merge of #87044 - cjgillot:expnhash, r=petrochenkov
[rust.git] / compiler / rustc_mir / src / const_eval / machine.rs
index 279f414e7fef14667bfb4d6e08061ccb70cf2731..f8b66badb8a4c2c3f8a9c0f1d760a539d192e6ca 100644 (file)
@@ -235,12 +235,15 @@ fn find_mir_or_eval_fn(
             // sensitive check here.  But we can at least rule out functions that are not const
             // at all.
             if !ecx.tcx.is_const_fn_raw(def.did) {
-                // Some functions we support even if they are non-const -- but avoid testing
-                // that for const fn!
-                ecx.hook_panic_fn(instance, args)?;
-                // We certainly do *not* want to actually call the fn
-                // though, so be sure we return here.
-                throw_unsup_format!("calling non-const function `{}`", instance)
+                // allow calling functions marked with #[default_method_body_is_const].
+                if !ecx.tcx.has_attr(def.did, sym::default_method_body_is_const) {
+                    // Some functions we support even if they are non-const -- but avoid testing
+                    // that for const fn!
+                    ecx.hook_panic_fn(instance, args)?;
+                    // We certainly do *not* want to actually call the fn
+                    // though, so be sure we return here.
+                    throw_unsup_format!("calling non-const function `{}`", instance)
+                }
             }
         }
         // This is a const fn. Call it.