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