File tree Expand file tree Collapse file tree 1 file changed +14
-1
lines changed
compiler/rustc_middle/src/mir Expand file tree Collapse file tree 1 file changed +14
-1
lines changed Original file line number Diff line number Diff line change @@ -293,7 +293,20 @@ impl<'tcx> Const<'tcx> {
293293
294294 #[ inline]
295295 pub fn try_eval_bits ( & self , tcx : TyCtxt < ' tcx > , param_env : ty:: ParamEnv < ' tcx > ) -> Option < u128 > {
296- let int = self . try_eval_scalar_int ( tcx, param_env) ?;
296+ debug_assert ! ( matches!(
297+ self . ty( ) . kind( ) ,
298+ ty:: Bool | ty:: Int ( _) | ty:: Uint ( _) | ty:: Float ( _) | ty:: Char
299+ ) ) ;
300+ let int = match self {
301+ // If the constant is already evaluated, we shortcut here.
302+ Const :: Ty ( c) if let ty:: ConstKind :: Value ( valtree) = c. kind ( ) => {
303+ valtree. unwrap_leaf ( )
304+ } ,
305+ // This is a more general form of the previous case.
306+ _ => {
307+ self . try_eval_scalar_int ( tcx, param_env) ?
308+ } ,
309+ } ;
297310 let size =
298311 tcx. layout_of ( param_env. with_reveal_all_normalized ( tcx) . and ( self . ty ( ) ) ) . ok ( ) ?. size ;
299312 int. to_bits ( size) . ok ( )
You can’t perform that action at this time.
0 commit comments