1
Fork 0

treat literals in ExprKind::StaticRef as mir::ConstantKind::Val

This commit is contained in:
b-naber 2022-03-07 13:51:59 +01:00
parent 1b14fd3b10
commit d92df974fe
6 changed files with 30 additions and 21 deletions

View file

@ -1,6 +1,7 @@
//! See docs in build/expr/mod.rs
use crate::build::Builder;
use rustc_middle::mir::interpret::{ConstValue, Scalar};
use rustc_middle::mir::*;
use rustc_middle::thir::*;
use rustc_middle::ty::CanonicalUserTypeAnnotation;
@ -26,8 +27,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
assert_eq!(literal.ty(), ty);
Constant { span, user_ty, literal: literal.into() }
}
ExprKind::StaticRef { literal, .. } => {
Constant { span, user_ty: None, literal: literal.into() }
ExprKind::StaticRef { alloc_id, ty, .. } => {
let const_val =
ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &this.tcx));
let literal = ConstantKind::Val(const_val, ty);
Constant { span, user_ty: None, literal }
}
ExprKind::ConstBlock { value } => {
Constant { span: span, user_ty: None, literal: value.into() }