Return ImmTy in discriminant_for_variant.
This commit is contained in:
parent
1d6a32c920
commit
d278ce126c
4 changed files with 11 additions and 13 deletions
|
@ -247,9 +247,9 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
&self,
|
||||
layout: TyAndLayout<'tcx>,
|
||||
variant: VariantIdx,
|
||||
) -> InterpResult<'tcx, Scalar<M::Provenance>> {
|
||||
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
|
||||
let discr_layout = self.layout_of(layout.ty.discriminant_ty(*self.tcx))?;
|
||||
Ok(match layout.ty.discriminant_for_variant(*self.tcx, variant) {
|
||||
let discr_value = match layout.ty.discriminant_for_variant(*self.tcx, variant) {
|
||||
Some(discr) => {
|
||||
// This type actually has discriminants.
|
||||
assert_eq!(discr.ty, discr_layout.ty);
|
||||
|
@ -260,6 +260,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
assert_eq!(variant.as_u32(), 0);
|
||||
Scalar::from_uint(variant.as_u32(), discr_layout.size)
|
||||
}
|
||||
})
|
||||
};
|
||||
Ok(ImmTy::from_scalar(discr_value, discr_layout))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -221,7 +221,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
sym::discriminant_value => {
|
||||
let place = self.deref_pointer(&args[0])?;
|
||||
let variant = self.read_discriminant(&place)?;
|
||||
let discr = self.discriminant_for_variant(place.layout, variant)?;
|
||||
let discr = self.discriminant_for_variant(place.layout, variant)?.to_scalar();
|
||||
self.write_scalar(discr, dest)?;
|
||||
}
|
||||
sym::exact_div => {
|
||||
|
|
|
@ -301,7 +301,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
|||
let op = self.eval_place_to_op(place, None)?;
|
||||
let variant = self.read_discriminant(&op)?;
|
||||
let discr = self.discriminant_for_variant(op.layout, variant)?;
|
||||
self.write_scalar(discr, &dest)?;
|
||||
self.write_immediate(*discr, &dest)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue