]> git.lizzy.rs Git - rust.git/commitdiff
use ConstantKind::Val in StaticRef
authorb-naber <bn263@gmx.de>
Tue, 8 Feb 2022 11:14:44 +0000 (12:14 +0100)
committerb-naber <bn263@gmx.de>
Tue, 15 Feb 2022 20:10:42 +0000 (21:10 +0100)
compiler/rustc_mir_build/src/build/expr/as_constant.rs

index 79ac09d523d079f55b7f5b4c6429a2b6d463d334..1136844377ab03eda9aef122e008d54260b5fdad 100644 (file)
@@ -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() }