@@ -627,50 +627,22 @@ fn codegen_stmt<'tcx>(
627627 ty:: Uint ( _) | ty:: Int ( _) => { }
628628 _ => unreachable ! ( "cast adt {} -> {}" , from_ty, to_ty) ,
629629 }
630+ let to_clif_ty = fx. clif_type ( to_ty) . unwrap ( ) ;
630631
631- use rustc_target:: abi:: { Int , TagEncoding , Variants } ;
632-
633- match operand. layout ( ) . variants {
634- Variants :: Single { index } => {
635- let discr = operand
636- . layout ( )
637- . ty
638- . discriminant_for_variant ( fx. tcx , index)
639- . unwrap ( ) ;
640- let discr = if discr. ty . is_signed ( ) {
641- fx. layout_of ( discr. ty ) . size . sign_extend ( discr. val )
642- } else {
643- discr. val
644- } ;
645- let discr = discr. into ( ) ;
646-
647- let discr = CValue :: const_val ( fx, fx. layout_of ( to_ty) , discr) ;
648- lval. write_cvalue ( fx, discr) ;
649- }
650- Variants :: Multiple {
651- ref tag,
652- tag_field,
653- tag_encoding : TagEncoding :: Direct ,
654- variants : _,
655- } => {
656- let cast_to = fx. clif_type ( dest_layout. ty ) . unwrap ( ) ;
657-
658- // Read the tag/niche-encoded discriminant from memory.
659- let encoded_discr =
660- operand. value_field ( fx, mir:: Field :: new ( tag_field) ) ;
661- let encoded_discr = encoded_discr. load_scalar ( fx) ;
662-
663- // Decode the discriminant (specifically if it's niche-encoded).
664- let signed = match tag. value {
665- Int ( _, signed) => signed,
666- _ => false ,
667- } ;
668- let val = clif_intcast ( fx, encoded_discr, cast_to, signed) ;
669- let val = CValue :: by_val ( val, dest_layout) ;
670- lval. write_cvalue ( fx, val) ;
671- }
672- Variants :: Multiple { .. } => unreachable ! ( ) ,
673- }
632+ let discriminant = crate :: discriminant:: codegen_get_discriminant (
633+ fx,
634+ operand,
635+ fx. layout_of ( operand. layout ( ) . ty . discriminant_ty ( fx. tcx ) ) ,
636+ )
637+ . load_scalar ( fx) ;
638+
639+ let res = crate :: cast:: clif_intcast (
640+ fx,
641+ discriminant,
642+ to_clif_ty,
643+ to_ty. is_signed ( ) ,
644+ ) ;
645+ lval. write_cvalue ( fx, CValue :: by_val ( res, dest_layout) ) ;
674646 } else {
675647 let to_clif_ty = fx. clif_type ( to_ty) . unwrap ( ) ;
676648 let from = operand. load_scalar ( fx) ;
0 commit comments