Skip to content

Commit b6e3bc2

Browse files
committed
remove an unnecessary special case in valtree_into_mplace
1 parent b66b322 commit b6e3bc2

File tree

1 file changed

+3
-40
lines changed

1 file changed

+3
-40
lines changed

compiler/rustc_const_eval/src/const_eval/valtrees.rs

+3-40
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::interpret::{
99
};
1010
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
1111
use rustc_span::source_map::DUMMY_SP;
12-
use rustc_target::abi::{Align, FieldIdx, VariantIdx, FIRST_VARIANT};
12+
use rustc_target::abi::{Align, VariantIdx};
1313

1414
#[instrument(skip(ecx), level = "debug")]
1515
fn branches<'tcx>(
@@ -399,45 +399,8 @@ fn valtree_into_mplace<'tcx>(
399399
debug!(?i, ?inner_valtree);
400400

401401
let place_inner = match ty.kind() {
402-
ty::Str | ty::Slice(_) => ecx.project_index(place, i as u64).unwrap(),
403-
_ if !ty.is_sized(*ecx.tcx, ty::ParamEnv::empty())
404-
&& i == branches.len() - 1 =>
405-
{
406-
// Note: For custom DSTs we need to manually process the last unsized field.
407-
// We created a `Pointer` for the `Allocation` of the complete sized version of
408-
// the Adt in `create_pointee_place` and now we fill that `Allocation` with the
409-
// values in the ValTree. For the unsized field we have to additionally add the meta
410-
// data.
411-
412-
let (unsized_inner_ty, num_elems) =
413-
get_info_on_unsized_field(ty, valtree, tcx);
414-
debug!(?unsized_inner_ty);
415-
416-
let inner_ty = match ty.kind() {
417-
ty::Adt(def, args) => {
418-
let i = FieldIdx::from_usize(i);
419-
def.variant(FIRST_VARIANT).fields[i].ty(tcx, args)
420-
}
421-
ty::Tuple(inner_tys) => inner_tys[i],
422-
_ => bug!("unexpected unsized type {:?}", ty),
423-
};
424-
425-
let inner_layout =
426-
tcx.layout_of(ty::ParamEnv::empty().and(inner_ty)).unwrap();
427-
debug!(?inner_layout);
428-
429-
let offset = place_adjusted.layout.fields.offset(i);
430-
place
431-
.offset_with_meta(
432-
offset,
433-
MemPlaceMeta::Meta(Scalar::from_target_usize(
434-
num_elems as u64,
435-
&tcx,
436-
)),
437-
inner_layout,
438-
&tcx,
439-
)
440-
.unwrap()
402+
ty::Str | ty::Slice(_) | ty::Array(..) => {
403+
ecx.project_index(place, i as u64).unwrap()
441404
}
442405
_ => ecx.project_field(&place_adjusted, i).unwrap(),
443406
};

0 commit comments

Comments
 (0)