about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/lib.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs
index 839cfd8d85a..4a00b9a5999 100644
--- a/compiler/rustc_const_eval/src/lib.rs
+++ b/compiler/rustc_const_eval/src/lib.rs
@@ -40,6 +40,13 @@ pub fn provide(providers: &mut Providers) {
     const_eval::provide(providers);
     providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
     providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
+    providers.eval_static_initializer_raw = |tcx, def_id| {
+        assert!(tcx.is_static(def_id));
+        let instance = ty::Instance::mono(tcx, def_id);
+        let gid = rustc_middle::mir::interpret::GlobalId { instance, promoted: None };
+        let param_env = ty::ParamEnv::reveal_all();
+        Ok(tcx.eval_to_allocation_raw(param_env.and(gid))?.alloc_id)
+    };
     providers.hooks.const_caller_location = util::caller_location::const_caller_location_provider;
     providers.eval_to_valtree = |tcx, param_env_and_value| {
         let (param_env, raw) = param_env_and_value.into_parts();