about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--compiler/rustc_mir_build/src/build/expr/as_constant.rs7
1 files changed, 6 insertions, 1 deletions
diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs
index 79ac09d523d..1136844377a 100644
--- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs
+++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs
@@ -27,7 +27,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
                 Constant { span, user_ty, literal: literal.into() }
             }
             ExprKind::StaticRef { literal, .. } => {
-                Constant { span, user_ty: None, literal: literal.into() }
+                let const_val = literal.val.try_to_value().unwrap_or_else(|| {
+                    bug!("expected `ConstKind::Value`, but found {:?}", literal.val)
+                });
+                let literal = ConstantKind::Val(const_val, literal.ty);
+
+                Constant { span, user_ty: None, literal }
             }
             ExprKind::ConstBlock { value } => {
                 Constant { span: span, user_ty: None, literal: value.into() }