@@ -23,7 +23,7 @@ use rustc_middle::ty::{
2323} ;
2424use rustc_span:: symbol:: Ident ;
2525use rustc_span:: { sym, Span , Symbol , DUMMY_SP } ;
26- use rustc_target:: abi:: { Size , VariantIdx } ;
26+ use rustc_target:: abi:: VariantIdx ;
2727use rustc_trait_selection:: traits:: query:: evaluate_obligation:: InferCtxtExt as _;
2828use rustc_trait_selection:: traits:: query:: normalize:: QueryNormalizeExt ;
2929use rustc_trait_selection:: traits:: { Obligation , ObligationCause } ;
@@ -865,22 +865,8 @@ impl core::ops::Add<u32> for EnumValue {
865865pub fn read_explicit_enum_value ( tcx : TyCtxt < ' _ > , id : DefId ) -> Option < EnumValue > {
866866 if let Ok ( ConstValue :: Scalar ( Scalar :: Int ( value) ) ) = tcx. const_eval_poly ( id) {
867867 match tcx. type_of ( id) . instantiate_identity ( ) . kind ( ) {
868- ty:: Int ( _) => Some ( EnumValue :: Signed ( match value. size ( ) . bytes ( ) {
869- 1 => i128:: from ( value. assert_bits ( Size :: from_bytes ( 1 ) ) as u8 as i8 ) ,
870- 2 => i128:: from ( value. assert_bits ( Size :: from_bytes ( 2 ) ) as u16 as i16 ) ,
871- 4 => i128:: from ( value. assert_bits ( Size :: from_bytes ( 4 ) ) as u32 as i32 ) ,
872- 8 => i128:: from ( value. assert_bits ( Size :: from_bytes ( 8 ) ) as u64 as i64 ) ,
873- 16 => value. assert_bits ( Size :: from_bytes ( 16 ) ) as i128 ,
874- _ => return None ,
875- } ) ) ,
876- ty:: Uint ( _) => Some ( EnumValue :: Unsigned ( match value. size ( ) . bytes ( ) {
877- 1 => value. assert_bits ( Size :: from_bytes ( 1 ) ) ,
878- 2 => value. assert_bits ( Size :: from_bytes ( 2 ) ) ,
879- 4 => value. assert_bits ( Size :: from_bytes ( 4 ) ) ,
880- 8 => value. assert_bits ( Size :: from_bytes ( 8 ) ) ,
881- 16 => value. assert_bits ( Size :: from_bytes ( 16 ) ) ,
882- _ => return None ,
883- } ) ) ,
868+ ty:: Int ( _) => Some ( EnumValue :: Signed ( value. to_int ( value. size ( ) ) ) ) ,
869+ ty:: Uint ( _) => Some ( EnumValue :: Unsigned ( value. to_uint ( value. size ( ) ) ) ) ,
884870 _ => None ,
885871 }
886872 } else {
0 commit comments