treat literals in ExprKind::StaticRef as mir::ConstantKind::Val
This commit is contained in:
parent
1b14fd3b10
commit
d92df974fe
6 changed files with 30 additions and 21 deletions
|
@ -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() }
|
||||
|
|
|
@ -8,7 +8,6 @@ use rustc_middle::hir::place::Place as HirPlace;
|
|||
use rustc_middle::hir::place::PlaceBase as HirPlaceBase;
|
||||
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
|
||||
use rustc_middle::middle::region;
|
||||
use rustc_middle::mir::interpret::Scalar;
|
||||
use rustc_middle::mir::{BinOp, BorrowKind, Field, UnOp};
|
||||
use rustc_middle::thir::*;
|
||||
use rustc_middle::ty::adjustment::{
|
||||
|
@ -941,15 +940,8 @@ impl<'tcx> Cx<'tcx> {
|
|||
let kind = if self.tcx.is_thread_local_static(id) {
|
||||
ExprKind::ThreadLocalRef(id)
|
||||
} else {
|
||||
let ptr = self.tcx.create_static_alloc(id);
|
||||
ExprKind::StaticRef {
|
||||
literal: ty::Const::from_scalar(
|
||||
self.tcx,
|
||||
Scalar::from_pointer(ptr.into(), &self.tcx),
|
||||
ty,
|
||||
),
|
||||
def_id: id,
|
||||
}
|
||||
let alloc_id = self.tcx.create_static_alloc(id);
|
||||
ExprKind::StaticRef { alloc_id, ty, def_id: id }
|
||||
};
|
||||
ExprKind::Deref {
|
||||
arg: self.thir.exprs.push(Expr { ty, temp_lifetime, span: expr.span, kind }),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue