@@ -795,43 +795,40 @@ pub fn trans_switch<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
795795 }
796796}
797797
798-
798+ pub fn is_discr_signed < ' tcx > ( r : & Repr < ' tcx > ) -> bool {
799+ match * r {
800+ CEnum ( ity, _, _) => ity. is_signed ( ) ,
801+ General ( ity, _, _) => ity. is_signed ( ) ,
802+ Univariant ( ..) => false ,
803+ RawNullablePointer { .. } => false ,
804+ StructWrappedNullablePointer { .. } => false ,
805+ }
806+ }
799807
800808/// Obtain the actual discriminant of a value.
801809pub fn trans_get_discr < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > , r : & Repr < ' tcx > ,
802810 scrutinee : ValueRef , cast_to : Option < Type > )
803811 -> ValueRef {
804- let signed;
805- let val;
806812 debug ! ( "trans_get_discr r: {:?}" , r) ;
807- match * r {
808- CEnum ( ity, min, max) => {
809- val = load_discr ( bcx, ity, scrutinee, min, max) ;
810- signed = ity. is_signed ( ) ;
811- }
813+ let val = match * r {
814+ CEnum ( ity, min, max) => load_discr ( bcx, ity, scrutinee, min, max) ,
812815 General ( ity, ref cases, _) => {
813816 let ptr = GEPi ( bcx, scrutinee, & [ 0 , 0 ] ) ;
814- val = load_discr ( bcx, ity, ptr, 0 , ( cases. len ( ) - 1 ) as Disr ) ;
815- signed = ity. is_signed ( ) ;
816- }
817- Univariant ( ..) => {
818- val = C_u8 ( bcx. ccx ( ) , 0 ) ;
819- signed = false ;
817+ load_discr ( bcx, ity, ptr, 0 , ( cases. len ( ) - 1 ) as Disr )
820818 }
819+ Univariant ( ..) => C_u8 ( bcx. ccx ( ) , 0 ) ,
821820 RawNullablePointer { nndiscr, nnty, .. } => {
822821 let cmp = if nndiscr == 0 { IntEQ } else { IntNE } ;
823822 let llptrty = type_of:: sizing_type_of ( bcx. ccx ( ) , nnty) ;
824- val = ICmp ( bcx, cmp, Load ( bcx, scrutinee) , C_null ( llptrty) , DebugLoc :: None ) ;
825- signed = false ;
823+ ICmp ( bcx, cmp, Load ( bcx, scrutinee) , C_null ( llptrty) , DebugLoc :: None )
826824 }
827825 StructWrappedNullablePointer { nndiscr, ref discrfield, .. } => {
828- val = struct_wrapped_nullable_bitdiscr ( bcx, nndiscr, discrfield, scrutinee) ;
829- signed = false ;
826+ struct_wrapped_nullable_bitdiscr ( bcx, nndiscr, discrfield, scrutinee)
830827 }
831- }
828+ } ;
832829 match cast_to {
833830 None => val,
834- Some ( llty) => if signed { SExt ( bcx, val, llty) } else { ZExt ( bcx, val, llty) }
831+ Some ( llty) => if is_discr_signed ( r ) { SExt ( bcx, val, llty) } else { ZExt ( bcx, val, llty) }
835832 }
836833}
837834
0 commit comments