Skip to content

Commit aa3a186

Browse files
committed
Remove deref_mir_constant
1 parent d030ece commit aa3a186

File tree

4 files changed

+1
-53
lines changed

4 files changed

+1
-53
lines changed

compiler/rustc_const_eval/src/const_eval/mod.rs

+1-38
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
use crate::errors::MaxNumNodesInConstErr;
44
use crate::interpret::{
5-
intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, MemPlaceMeta,
6-
Scalar,
5+
intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, Scalar,
76
};
8-
use rustc_hir::Mutability;
97
use rustc_middle::mir;
108
use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId};
119
use rustc_middle::ty::{self, TyCtxt};
@@ -131,38 +129,3 @@ pub(crate) fn try_destructure_mir_constant<'tcx>(
131129

132130
Ok(mir::DestructuredConstant { variant, fields })
133131
}
134-
135-
#[instrument(skip(tcx), level = "debug")]
136-
pub(crate) fn deref_mir_constant<'tcx>(
137-
tcx: TyCtxt<'tcx>,
138-
param_env: ty::ParamEnv<'tcx>,
139-
val: mir::ConstantKind<'tcx>,
140-
) -> mir::ConstantKind<'tcx> {
141-
let ecx = mk_eval_cx(tcx, DUMMY_SP, param_env, false);
142-
let op = ecx.eval_mir_constant(&val, None, None).unwrap();
143-
let mplace = ecx.deref_operand(&op).unwrap();
144-
if let Some(alloc_id) = mplace.ptr.provenance {
145-
assert_eq!(
146-
tcx.global_alloc(alloc_id).unwrap_memory().0.0.mutability,
147-
Mutability::Not,
148-
"deref_mir_constant cannot be used with mutable allocations as \
149-
that could allow pattern matching to observe mutable statics",
150-
);
151-
}
152-
153-
let ty = match mplace.meta {
154-
MemPlaceMeta::None => mplace.layout.ty,
155-
// In case of unsized types, figure out the real type behind.
156-
MemPlaceMeta::Meta(scalar) => match mplace.layout.ty.kind() {
157-
ty::Str => bug!("there's no sized equivalent of a `str`"),
158-
ty::Slice(elem_ty) => tcx.mk_array(*elem_ty, scalar.to_target_usize(&tcx).unwrap()),
159-
_ => bug!(
160-
"type {} should not have metadata, but had {:?}",
161-
mplace.layout.ty,
162-
mplace.meta
163-
),
164-
},
165-
};
166-
167-
mir::ConstantKind::Val(op_to_const(&ecx, &mplace.into()), ty)
168-
}

compiler/rustc_const_eval/src/lib.rs

-4
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,6 @@ pub fn provide(providers: &mut Providers) {
5656
providers.valtree_to_const_val = |tcx, (ty, valtree)| {
5757
const_eval::valtree_to_const_value(tcx, ty::ParamEnv::empty().and(ty), valtree)
5858
};
59-
providers.deref_mir_constant = |tcx, param_env_and_value| {
60-
let (param_env, value) = param_env_and_value.into_parts();
61-
const_eval::deref_mir_constant(tcx, param_env, value)
62-
};
6359
providers.check_validity_requirement = |tcx, (init_kind, param_env_and_ty)| {
6460
util::check_validity_requirement(tcx, init_kind, param_env_and_ty)
6561
};

compiler/rustc_middle/src/query/mod.rs

-8
Original file line numberDiff line numberDiff line change
@@ -1081,14 +1081,6 @@ rustc_queries! {
10811081
desc { "destructuring MIR constant"}
10821082
}
10831083

1084-
/// Dereference a constant reference or raw pointer and turn the result into a constant
1085-
/// again.
1086-
query deref_mir_constant(
1087-
key: ty::ParamEnvAnd<'tcx, mir::ConstantKind<'tcx>>
1088-
) -> mir::ConstantKind<'tcx> {
1089-
desc { "dereferencing MIR constant" }
1090-
}
1091-
10921084
query const_caller_location(key: (rustc_span::Symbol, u32, u32)) -> ConstValue<'tcx> {
10931085
desc { "getting a &core::panic::Location referring to a span" }
10941086
}

compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs

-3
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,6 @@ impl<'tcx> ConstToPat<'tcx> {
464464
// deref pattern.
465465
_ => {
466466
if !pointee_ty.is_sized(tcx, param_env) {
467-
// `tcx.deref_mir_constant()` below will ICE with an unsized type
468-
// (except slices, which are handled in a separate arm above).
469-
470467
let err = UnsizedPattern { span, non_sm_ty: *pointee_ty };
471468
tcx.sess.emit_err(err);
472469

0 commit comments

Comments
 (0)