Skip to content

Commit

Permalink
safe transmute: use to_valtree to destructure const Assume
Browse files Browse the repository at this point in the history
  • Loading branch information
jswrenn committed Aug 31, 2022
1 parent 1d844fe commit fbcc038
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions compiler/rustc_transmute/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit fbcc038

Please sign in to comment.