about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2021-07-10 11:17:14 +0800
committerDeadbeef <ent3rm4n@gmail.com>2021-07-10 20:54:50 +0800
commit5e695bbba1a682735e850e4e348804edb169bf53 (patch)
tree04dc9e033e8bba0f53f3957df428652fa15d61c9
parent554fad7bdac1655119f2450d3286463aa2290200 (diff)
downloadrust-5e695bbba1a682735e850e4e348804edb169bf53.tar.gz
rust-5e695bbba1a682735e850e4e348804edb169bf53.zip
Update CTFE to allow fns marked with the attr
-rw-r--r--compiler/rustc_mir/src/const_eval/machine.rs15
1 files changed, 9 insertions, 6 deletions
diff --git a/compiler/rustc_mir/src/const_eval/machine.rs b/compiler/rustc_mir/src/const_eval/machine.rs
index 279f414e7fe..f8b66badb8a 100644
--- a/compiler/rustc_mir/src/const_eval/machine.rs
+++ b/compiler/rustc_mir/src/const_eval/machine.rs
@@ -235,12 +235,15 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
             // 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.