about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorDominik Stolz <d.stolz@tum.de>2022-06-28 22:35:48 +0200
committerDominik Stolz <d.stolz@tum.de>2022-06-28 22:38:32 +0200
commitcd88bb332c40deda6db2c18c0bc03cfd0da42055 (patch)
treea8c6e05321adf47e899a2b44f233ff270ff4fecc /compiler/rustc_const_eval/src
parent94e93749ab00539a11e90426ea87382c433530a8 (diff)
downloadrust-cd88bb332c40deda6db2c18c0bc03cfd0da42055.tar.gz
rust-cd88bb332c40deda6db2c18c0bc03cfd0da42055.zip
Improve pretty printing of valtrees for references
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/const_eval/mod.rs78
-rw-r--r--compiler/rustc_const_eval/src/lib.rs1
2 files changed, 0 insertions, 79 deletions
diff --git a/compiler/rustc_const_eval/src/const_eval/mod.rs b/compiler/rustc_const_eval/src/const_eval/mod.rs
index a1d2e5cf3ef..bf65fdc54ca 100644
--- a/compiler/rustc_const_eval/src/const_eval/mod.rs
+++ b/compiler/rustc_const_eval/src/const_eval/mod.rs
@@ -5,7 +5,6 @@ use rustc_middle::mir;
 use rustc_middle::mir::interpret::{EvalToValTreeResult, GlobalId};
 use rustc_middle::ty::{self, TyCtxt};
 use rustc_span::{source_map::DUMMY_SP, symbol::Symbol};
-use rustc_target::abi::VariantIdx;
 
 use crate::interpret::{
     intern_const_alloc_recursive, ConstValue, InternKind, InterpCx, InterpResult, MemPlaceMeta,
@@ -91,83 +90,6 @@ pub(crate) fn eval_to_valtree<'tcx>(
     }
 }
 
-/// Tries to destructure constants of type Array or Adt into the constants
-/// of its fields.
-pub(crate) fn try_destructure_const<'tcx>(
-    tcx: TyCtxt<'tcx>,
-    const_: ty::Const<'tcx>,
-) -> Option<ty::DestructuredConst<'tcx>> {
-    if let ty::ConstKind::Value(valtree) = const_.kind() {
-        let branches = match valtree {
-            ty::ValTree::Branch(b) => b,
-            _ => return None,
-        };
-
-        let (fields, variant) = match const_.ty().kind() {
-            ty::Array(inner_ty, _) | ty::Slice(inner_ty) => {
-                // construct the consts for the elements of the array/slice
-                let field_consts = branches
-                    .iter()
-                    .map(|b| {
-                        tcx.mk_const(ty::ConstS { kind: ty::ConstKind::Value(*b), ty: *inner_ty })
-                    })
-                    .collect::<Vec<_>>();
-                debug!(?field_consts);
-
-                (field_consts, None)
-            }
-            ty::Adt(def, _) if def.variants().is_empty() => bug!("unreachable"),
-            ty::Adt(def, substs) => {
-                let variant_idx = if def.is_enum() {
-                    VariantIdx::from_u32(branches[0].unwrap_leaf().try_to_u32().ok()?)
-                } else {
-                    VariantIdx::from_u32(0)
-                };
-                let fields = &def.variant(variant_idx).fields;
-                let mut field_consts = Vec::with_capacity(fields.len());
-
-                // Note: First element inValTree corresponds to variant of enum
-                let mut valtree_idx = if def.is_enum() { 1 } else { 0 };
-                for field in fields {
-                    let field_ty = field.ty(tcx, substs);
-                    let field_valtree = branches[valtree_idx]; // first element of branches is variant
-                    let field_const = tcx.mk_const(ty::ConstS {
-                        kind: ty::ConstKind::Value(field_valtree),
-                        ty: field_ty,
-                    });
-                    field_consts.push(field_const);
-                    valtree_idx += 1;
-                }
-                debug!(?field_consts);
-
-                (field_consts, Some(variant_idx))
-            }
-            ty::Tuple(elem_tys) => {
-                let fields = elem_tys
-                    .iter()
-                    .enumerate()
-                    .map(|(i, elem_ty)| {
-                        let elem_valtree = branches[i];
-                        tcx.mk_const(ty::ConstS {
-                            kind: ty::ConstKind::Value(elem_valtree),
-                            ty: elem_ty,
-                        })
-                    })
-                    .collect::<Vec<_>>();
-
-                (fields, None)
-            }
-            _ => bug!("cannot destructure constant {:?}", const_),
-        };
-
-        let fields = tcx.arena.alloc_from_iter(fields.into_iter());
-
-        Some(ty::DestructuredConst { variant, fields })
-    } else {
-        None
-    }
-}
-
 #[instrument(skip(tcx), level = "debug")]
 pub(crate) fn try_destructure_mir_constant<'tcx>(
     tcx: TyCtxt<'tcx>,
diff --git a/compiler/rustc_const_eval/src/lib.rs b/compiler/rustc_const_eval/src/lib.rs
index 64a74e9d7e2..5bf91879066 100644
--- a/compiler/rustc_const_eval/src/lib.rs
+++ b/compiler/rustc_const_eval/src/lib.rs
@@ -42,7 +42,6 @@ pub fn provide(providers: &mut Providers) {
     providers.eval_to_const_value_raw = const_eval::eval_to_const_value_raw_provider;
     providers.eval_to_allocation_raw = const_eval::eval_to_allocation_raw_provider;
     providers.const_caller_location = const_eval::const_caller_location;
-    providers.try_destructure_const = |tcx, val| const_eval::try_destructure_const(tcx, val);
     providers.eval_to_valtree = |tcx, param_env_and_value| {
         let (param_env, raw) = param_env_and_value.into_parts();
         const_eval::eval_to_valtree(tcx, param_env, raw)