From fbcc038a224e58f7d3aca25c7f2321f11ce5513d Mon Sep 17 00:00:00 2001 From: Jack Wrenn Date: Wed, 31 Aug 2022 18:17:32 +0000 Subject: [PATCH] safe transmute: use `to_valtree` to destructure const `Assume` ref: https://github.com/rust-lang/rust/pull/100726#discussion_r954813220 --- compiler/rustc_transmute/src/lib.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/compiler/rustc_transmute/src/lib.rs b/compiler/rustc_transmute/src/lib.rs index 68270a603a146..2a1a81315657c 100644 --- a/compiler/rustc_transmute/src/lib.rs +++ b/compiler/rustc_transmute/src/lib.rs @@ -123,7 +123,7 @@ mod rustc { param_env: ParamEnv<'tcx>, c: Const<'tcx>, ) -> Self { - use rustc_middle::ty::DestructuredConst; + use rustc_middle::ty::ScalarInt; use rustc_middle::ty::TypeVisitable; use rustc_span::symbol::sym; @@ -142,9 +142,8 @@ mod rustc { LangItem::TransmuteOpts.name(), ); - let DestructuredConst { variant, fields } = tcx.destructure_const(c); - let variant_idx = variant.expect("The given `Const` must be an ADT."); - let variant = adt_def.variant(variant_idx); + let variant = adt_def.non_enum_variant(); + let fields = c.to_valtree().unwrap_branch(); let get_field = |name| { let (field_idx, _) = variant @@ -153,9 +152,7 @@ mod rustc { .enumerate() .find(|(_, field_def)| name == field_def.name) .expect(&format!("There were no fields named `{name}`.")); - fields[field_idx].try_eval_bool(tcx, param_env).expect(&format!( - "The field named `{name}` lang item could not be evaluated to a bool." - )) + fields[field_idx].unwrap_leaf() == ScalarInt::TRUE }; Self {