use AllocId and Ty in ExprKind::StaticRef and delay ConstValue construction
This commit is contained in:
parent
54ff25e446
commit
fff06e5edc
4 changed files with 16 additions and 18 deletions
|
@ -17,6 +17,7 @@ use rustc_index::newtype_index;
|
||||||
use rustc_index::vec::IndexVec;
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_middle::infer::canonical::Canonical;
|
use rustc_middle::infer::canonical::Canonical;
|
||||||
use rustc_middle::middle::region;
|
use rustc_middle::middle::region;
|
||||||
|
use rustc_middle::mir::interpret::AllocId;
|
||||||
use rustc_middle::mir::{
|
use rustc_middle::mir::{
|
||||||
BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp, UserTypeProjection,
|
BinOp, BorrowKind, FakeReadCause, Field, Mutability, UnOp, UserTypeProjection,
|
||||||
};
|
};
|
||||||
|
@ -419,7 +420,8 @@ pub enum ExprKind<'tcx> {
|
||||||
/// This is only distinguished from `Literal` so that we can register some
|
/// This is only distinguished from `Literal` so that we can register some
|
||||||
/// info for diagnostics.
|
/// info for diagnostics.
|
||||||
StaticRef {
|
StaticRef {
|
||||||
literal: Const<'tcx>,
|
alloc_id: AllocId,
|
||||||
|
ty: Ty<'tcx>,
|
||||||
def_id: DefId,
|
def_id: DefId,
|
||||||
},
|
},
|
||||||
/// Inline assembly, i.e. `asm!()`.
|
/// Inline assembly, i.e. `asm!()`.
|
||||||
|
@ -715,7 +717,11 @@ impl<'tcx> fmt::Display for Pat<'tcx> {
|
||||||
Some(&adt_def.variants[variant_index])
|
Some(&adt_def.variants[variant_index])
|
||||||
}
|
}
|
||||||
_ => self.ty.ty_adt_def().and_then(|adt| {
|
_ => self.ty.ty_adt_def().and_then(|adt| {
|
||||||
if !adt.is_enum() { Some(adt.non_enum_variant()) } else { None }
|
if !adt.is_enum() {
|
||||||
|
Some(adt.non_enum_variant())
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -123,7 +123,7 @@ pub fn walk_expr<'a, 'tcx: 'a, V: Visitor<'a, 'tcx>>(visitor: &mut V, expr: &Exp
|
||||||
}
|
}
|
||||||
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
|
Closure { closure_id: _, substs: _, upvars: _, movability: _, fake_reads: _ } => {}
|
||||||
Literal { literal, user_ty: _, const_id: _ } => visitor.visit_const(literal),
|
Literal { literal, user_ty: _, const_id: _ } => visitor.visit_const(literal),
|
||||||
StaticRef { literal, def_id: _ } => visitor.visit_const(literal),
|
StaticRef { .. } => {}
|
||||||
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
|
InlineAsm { ref operands, template: _, options: _, line_spans: _ } => {
|
||||||
for op in &**operands {
|
for op in &**operands {
|
||||||
use InlineAsmOperand::*;
|
use InlineAsmOperand::*;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! See docs in build/expr/mod.rs
|
//! See docs in build/expr/mod.rs
|
||||||
|
|
||||||
use crate::build::Builder;
|
use crate::build::Builder;
|
||||||
|
use rustc_middle::mir::interpret::{ConstValue, Scalar};
|
||||||
use rustc_middle::mir::*;
|
use rustc_middle::mir::*;
|
||||||
use rustc_middle::thir::*;
|
use rustc_middle::thir::*;
|
||||||
use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
use rustc_middle::ty::CanonicalUserTypeAnnotation;
|
||||||
|
@ -26,11 +27,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
assert_eq!(literal.ty(), ty);
|
assert_eq!(literal.ty(), ty);
|
||||||
Constant { span, user_ty, literal: literal.into() }
|
Constant { span, user_ty, literal: literal.into() }
|
||||||
}
|
}
|
||||||
ExprKind::StaticRef { literal, .. } => {
|
ExprKind::StaticRef { alloc_id, ty, .. } => {
|
||||||
let const_val = literal.val.try_to_value().unwrap_or_else(|| {
|
let const_val =
|
||||||
bug!("expected `ConstKind::Value`, but found {:?}", literal.val)
|
ConstValue::Scalar(Scalar::from_pointer(alloc_id.into(), &this.tcx));
|
||||||
});
|
let literal = ConstantKind::Val(const_val, ty);
|
||||||
let literal = ConstantKind::Val(const_val, literal.ty);
|
|
||||||
|
|
||||||
Constant { span, user_ty: None, literal }
|
Constant { span, user_ty: None, literal }
|
||||||
}
|
}
|
||||||
|
|
|
@ -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::PlaceBase as HirPlaceBase;
|
||||||
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
|
use rustc_middle::hir::place::ProjectionKind as HirProjectionKind;
|
||||||
use rustc_middle::middle::region;
|
use rustc_middle::middle::region;
|
||||||
use rustc_middle::mir::interpret::Scalar;
|
|
||||||
use rustc_middle::mir::{BinOp, BorrowKind, Field, UnOp};
|
use rustc_middle::mir::{BinOp, BorrowKind, Field, UnOp};
|
||||||
use rustc_middle::thir::*;
|
use rustc_middle::thir::*;
|
||||||
use rustc_middle::ty::adjustment::{
|
use rustc_middle::ty::adjustment::{
|
||||||
|
@ -943,15 +942,8 @@ impl<'tcx> Cx<'tcx> {
|
||||||
let kind = if self.tcx.is_thread_local_static(id) {
|
let kind = if self.tcx.is_thread_local_static(id) {
|
||||||
ExprKind::ThreadLocalRef(id)
|
ExprKind::ThreadLocalRef(id)
|
||||||
} else {
|
} else {
|
||||||
let ptr = self.tcx.create_static_alloc(id);
|
let alloc_id = self.tcx.create_static_alloc(id);
|
||||||
ExprKind::StaticRef {
|
ExprKind::StaticRef { alloc_id, ty, def_id: id }
|
||||||
literal: ty::Const::from_scalar(
|
|
||||||
self.tcx,
|
|
||||||
Scalar::from_pointer(ptr.into(), &self.tcx),
|
|
||||||
ty,
|
|
||||||
),
|
|
||||||
def_id: id,
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
ExprKind::Deref {
|
ExprKind::Deref {
|
||||||
arg: self.thir.exprs.push(Expr { ty, temp_lifetime, span: expr.span, kind }),
|
arg: self.thir.exprs.push(Expr { ty, temp_lifetime, span: expr.span, kind }),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue