Remove deref_mir_constant
This commit is contained in:
parent
d030ece6f7
commit
aa3a1862ba
@ -2,10 +2,8 @@
|
|||||||
|
|
||||||
use crate::errors::MaxNumNodesInConstErr;
|
use crate::errors::MaxNumNodesInConstErr;
|
||||||
use crate::interpret::{
|
use crate::interpret::{
|
||||||
intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, MemPlaceMeta,
|
intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, Scalar,
|
||||||
Scalar,
|
|
||||||
};
|
};
|
||||||
use rustc_hir::Mutability;
|
|
||||||
use rustc_middle::mir;
|
use rustc_middle::mir;
|
||||||
use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId};
|
use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId};
|
||||||
use rustc_middle::ty::{self, TyCtxt};
|
use rustc_middle::ty::{self, TyCtxt};
|
||||||
@ -131,38 +129,3 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
|
|||||||
|
|
||||||
Ok(mir::DestructuredConstant { variant, fields })
|
Ok(mir::DestructuredConstant { variant, fields })
|
||||||
}
|
}
|
||||||
|
|
||||||
#[instrument(skip(tcx), level = "debug")]
|
|
||||||
pub(crate) fn deref_mir_constant<'tcx>(
|
|
||||||
tcx: TyCtxt<'tcx>,
|
|
||||||
param_env: ty::ParamEnv<'tcx>,
|
|
||||||
val: mir::ConstantKind<'tcx>,
|
|
||||||
) -> mir::ConstantKind<'tcx> {
|
|
||||||
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
|
|
||||||
let op = ecx.eval_mir_constant(&val, None, None).unwrap();
|
|
||||||
let mplace = ecx.deref_operand(&op).unwrap();
|
|
||||||
if let Some(alloc_id) = mplace.ptr.provenance {
|
|
||||||
assert_eq!(
|
|
||||||
tcx.global_alloc(alloc_id).unwrap_memory().0.0.mutability,
|
|
||||||
Mutability::Not,
|
|
||||||
"deref_mir_constant cannot be used with mutable allocations as \
|
|
||||||
that could allow pattern matching to observe mutable statics",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
let ty = match mplace.meta {
|
|
||||||
MemPlaceMeta::None => mplace.layout.ty,
|
|
||||||
// In case of unsized types, figure out the real type behind.
|
|
||||||
MemPlaceMeta::Meta(scalar) => match mplace.layout.ty.kind() {
|
|
||||||
ty::Str => bug!("there's no sized equivalent of a `str`"),
|
|
||||||
ty::Slice(elem_ty) => tcx.mk_array(*elem_ty, scalar.to_target_usize(&tcx).unwrap()),
|
|
||||||
_ => bug!(
|
|
||||||
"type {} should not have metadata, but had {:?}",
|
|
||||||
mplace.layout.ty,
|
|
||||||
mplace.meta
|
|
||||||
),
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
mir::ConstantKind::Val(op_to_const(&ecx, &mplace.into()), ty)
|
|
||||||
}
|
|
||||||
|
@ -56,10 +56,6 @@ pub fn provide(providers: &mut Providers) {
|
|||||||
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
|
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
|
||||||
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
|
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
|
||||||
};
|
};
|
||||||
providers.deref_mir_constant = |tcx, param_env_and_value| {
|
|
||||||
let (param_env, value) = param_env_and_value.into_parts();
|
|
||||||
const_eval::deref_mir_constant(tcx, param_env, value)
|
|
||||||
};
|
|
||||||
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
|
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
|
||||||
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
|
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
|
||||||
};
|
};
|
||||||
|
@ -1081,14 +1081,6 @@
|
|||||||
desc { "destructuring MIR constant"}
|
desc { "destructuring MIR constant"}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dereference a constant reference or raw pointer and turn the result into a constant
|
|
||||||
/// again.
|
|
||||||
query deref_mir_constant(
|
|
||||||
key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
|
|
||||||
) -> mir::ConstantKind<'tcx> {
|
|
||||||
desc { "dereferencing MIR constant" }
|
|
||||||
}
|
|
||||||
|
|
||||||
query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
|
query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
|
||||||
desc { "getting a &core::panic::Location referring to a span" }
|
desc { "getting a &core::panic::Location referring to a span" }
|
||||||
}
|
}
|
||||||
|
@ -464,9 +464,6 @@ fn recur(
|
|||||||
// deref pattern.
|
// deref pattern.
|
||||||
_ => {
|
_ => {
|
||||||
if !pointee_ty.is_sized(tcx, param_env) {
|
if !pointee_ty.is_sized(tcx, param_env) {
|
||||||
// `tcx.deref_mir_constant()` below will ICE with an unsized type
|
|
||||||
// (except slices, which are handled in a separate arm above).
|
|
||||||
|
|
||||||
let err = UnsizedPattern { span, non_sm_ty: *pointee_ty };
|
let err = UnsizedPattern { span, non_sm_ty: *pointee_ty };
|
||||||
tcx.sess.emit_err(err);
|
tcx.sess.emit_err(err);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user