@@ -61,7 +61,7 @@ use rustc_middle::ty::layout::IntegerExt;
6161use rustc_middle:: ty:: { self , Ty , TyCtxt , VariantDef } ;
6262use rustc_session:: lint;
6363use rustc_span:: { Span , DUMMY_SP } ;
64- use rustc_target:: abi:: { FieldIdx , Integer , Primitive , Size , VariantIdx , FIRST_VARIANT } ;
64+ use rustc_target:: abi:: { FieldIdx , Integer , VariantIdx , FIRST_VARIANT } ;
6565
6666use self :: Constructor :: * ;
6767use self :: SliceKind :: * ;
@@ -86,35 +86,6 @@ fn expand_or_pat<'p, 'tcx>(pat: &'p Pat<'tcx>) -> Vec<&'p Pat<'tcx>> {
8686 pats
8787}
8888
89- /// Evaluate an int constant, with a faster branch for a common case.
90- #[ inline]
91- fn fast_try_eval_bits < ' tcx > (
92- tcx : TyCtxt < ' tcx > ,
93- param_env : ty:: ParamEnv < ' tcx > ,
94- value : & mir:: Const < ' tcx > ,
95- ) -> Option < u128 > {
96- let int = match value {
97- // If the constant is already evaluated, we shortcut here.
98- mir:: Const :: Ty ( c) if let ty:: ConstKind :: Value ( valtree) = c. kind ( ) => {
99- valtree. unwrap_leaf ( )
100- } ,
101- // This is a more general form of the previous case.
102- _ => {
103- value. try_eval_scalar_int ( tcx, param_env) ?
104- } ,
105- } ;
106- let size = match value. ty ( ) . kind ( ) {
107- ty:: Bool => Size :: from_bytes ( 1 ) ,
108- ty:: Char => Size :: from_bytes ( 4 ) ,
109- ty:: Int ( ity) => Integer :: from_int_ty ( & tcx, * ity) . size ( ) ,
110- ty:: Uint ( uty) => Integer :: from_uint_ty ( & tcx, * uty) . size ( ) ,
111- ty:: Float ( ty:: FloatTy :: F32 ) => Primitive :: F32 . size ( & tcx) ,
112- ty:: Float ( ty:: FloatTy :: F64 ) => Primitive :: F64 . size ( & tcx) ,
113- _ => return None ,
114- } ;
115- int. to_bits ( size) . ok ( )
116- }
117-
11889/// An inclusive interval, used for precise integer exhaustiveness checking.
11990/// `IntRange`s always store a contiguous range. This means that values are
12091/// encoded such that `0` encodes the minimum value for the integer,
@@ -1346,14 +1317,14 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
13461317 PatKind :: Constant { value } => {
13471318 match pat. ty . kind ( ) {
13481319 ty:: Bool | ty:: Char | ty:: Int ( _) | ty:: Uint ( _) => {
1349- ctor = match fast_try_eval_bits ( cx. tcx , cx. param_env , value ) {
1320+ ctor = match value . try_eval_bits ( cx. tcx , cx. param_env ) {
13501321 Some ( bits) => IntRange ( IntRange :: from_bits ( cx. tcx , pat. ty , bits) ) ,
13511322 None => Opaque ,
13521323 } ;
13531324 fields = Fields :: empty ( ) ;
13541325 }
13551326 ty:: Float ( ty:: FloatTy :: F32 ) => {
1356- ctor = match fast_try_eval_bits ( cx. tcx , cx. param_env , value ) {
1327+ ctor = match value . try_eval_bits ( cx. tcx , cx. param_env ) {
13571328 Some ( bits) => {
13581329 use rustc_apfloat:: Float ;
13591330 let value = rustc_apfloat:: ieee:: Single :: from_bits ( bits) ;
@@ -1364,7 +1335,7 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
13641335 fields = Fields :: empty ( ) ;
13651336 }
13661337 ty:: Float ( ty:: FloatTy :: F64 ) => {
1367- ctor = match fast_try_eval_bits ( cx. tcx , cx. param_env , value ) {
1338+ ctor = match value . try_eval_bits ( cx. tcx , cx. param_env ) {
13681339 Some ( bits) => {
13691340 use rustc_apfloat:: Float ;
13701341 let value = rustc_apfloat:: ieee:: Double :: from_bits ( bits) ;
@@ -1399,8 +1370,8 @@ impl<'p, 'tcx> DeconstructedPat<'p, 'tcx> {
13991370 PatKind :: Range ( box PatRange { lo, hi, end } ) => {
14001371 use rustc_apfloat:: Float ;
14011372 let ty = lo. ty ( ) ;
1402- let lo = fast_try_eval_bits ( cx. tcx , cx. param_env , lo ) . unwrap ( ) ;
1403- let hi = fast_try_eval_bits ( cx. tcx , cx. param_env , hi ) . unwrap ( ) ;
1373+ let lo = lo . try_eval_bits ( cx. tcx , cx. param_env ) . unwrap ( ) ;
1374+ let hi = hi . try_eval_bits ( cx. tcx , cx. param_env ) . unwrap ( ) ;
14041375 ctor = match ty. kind ( ) {
14051376 ty:: Char | ty:: Int ( _) | ty:: Uint ( _) => {
14061377 IntRange ( IntRange :: from_range ( cx. tcx , lo, hi, ty, * end) )
0 commit comments