@@ -54,7 +54,6 @@ use rustc_index::vec::Idx;
54
54
55
55
use rustc_hir:: def_id:: DefId ;
56
56
use rustc_hir:: { HirId , RangeEnd } ;
57
- use rustc_middle:: mir:: interpret:: ConstValue ;
58
57
use rustc_middle:: mir:: Field ;
59
58
use rustc_middle:: ty:: layout:: IntegerExt ;
60
59
use rustc_middle:: ty:: { self , Const , Ty , TyCtxt } ;
@@ -116,26 +115,20 @@ impl IntRange {
116
115
param_env : ty:: ParamEnv < ' tcx > ,
117
116
value : & Const < ' tcx > ,
118
117
) -> Option < IntRange > {
119
- if let Some ( ( target_size, bias) ) = Self :: integral_size_and_signed_bias ( tcx, value. ty ) {
120
- let ty = value. ty ;
121
- let val = ( || {
122
- if let ty:: ConstKind :: Value ( ConstValue :: Scalar ( scalar) ) = value. val {
123
- // For this specific pattern we can skip a lot of effort and go
124
- // straight to the result, after doing a bit of checking. (We
125
- // could remove this branch and just fall through, which
126
- // is more general but much slower.)
127
- if let Ok ( bits) = scalar. to_bits_or_ptr ( target_size, & tcx) {
128
- return Some ( bits) ;
129
- }
130
- }
131
- // This is a more general form of the previous case.
132
- value. try_eval_bits ( tcx, param_env, ty)
133
- } ) ( ) ?;
134
- let val = val ^ bias;
135
- Some ( IntRange { range : val..=val } )
118
+ let ( target_size, bias) = Self :: integral_size_and_signed_bias ( tcx, value. ty ) ?;
119
+ let ty = value. ty ;
120
+ let val = if let Some ( int) = value. val . try_to_scalar_int ( ) {
121
+ // For this specific pattern we can skip a lot of effort and go
122
+ // straight to the result, after doing a bit of checking. (We
123
+ // could remove this branch and just always use try_eval_bits, which
124
+ // is more general but much slower.)
125
+ int. assert_bits ( target_size)
136
126
} else {
137
- None
138
- }
127
+ // This is a more general form of the previous case.
128
+ value. try_eval_bits ( tcx, param_env, ty) ?
129
+ } ;
130
+ let val = val ^ bias;
131
+ Some ( IntRange { range : val..=val } )
139
132
}
140
133
141
134
#[ inline]
0 commit comments