@@ -269,9 +269,12 @@ struct SimplifyToExp {
269
269
270
270
#[ derive( Clone , Copy ) ]
271
271
enum CompareType < ' tcx , ' a > {
272
+ /// Identical statements.
272
273
Same ( & ' a StatementKind < ' tcx > ) ,
274
+ /// Assignment statements have the same value.
273
275
Eq ( & ' a Place < ' tcx > , Ty < ' tcx > , ScalarInt ) ,
274
- Discr ( & ' a Place < ' tcx > , Ty < ' tcx > , bool ) ,
276
+ /// Enum variant comparison type.
277
+ Discr { place : & ' a Place < ' tcx > , ty : Ty < ' tcx > , is_signed : bool } ,
275
278
}
276
279
277
280
enum TransfromType {
@@ -285,7 +288,7 @@ impl From<CompareType<'_, '_>> for TransfromType {
285
288
match compare_type {
286
289
CompareType :: Same ( _) => TransfromType :: Same ,
287
290
CompareType :: Eq ( _, _, _) => TransfromType :: Eq ,
288
- CompareType :: Discr ( _ , _ , _ ) => TransfromType :: Discr ,
291
+ CompareType :: Discr { .. } => TransfromType :: Discr ,
289
292
}
290
293
}
291
294
}
@@ -402,11 +405,11 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
402
405
&& Some ( s)
403
406
== ScalarInt :: try_from_uint ( second_val, s. size ( ) ) ) =>
404
407
{
405
- CompareType :: Discr (
406
- lhs_f,
407
- f_c. const_ . ty ( ) ,
408
- f_c. const_ . ty ( ) . is_signed ( ) || discr_ty. is_signed ( ) ,
409
- )
408
+ CompareType :: Discr {
409
+ place : lhs_f,
410
+ ty : f_c. const_ . ty ( ) ,
411
+ is_signed : f_c. const_ . ty ( ) . is_signed ( ) || discr_ty. is_signed ( ) ,
412
+ }
410
413
}
411
414
_ => {
412
415
return false ;
@@ -436,7 +439,7 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
436
439
&& s_c. const_ . ty ( ) == f_ty
437
440
&& s_c. const_ . try_eval_scalar_int ( tcx, param_env) == Some ( val) => { }
438
441
(
439
- CompareType :: Discr ( lhs_f, f_ty, is_signed) ,
442
+ CompareType :: Discr { place : lhs_f, ty : f_ty, is_signed } ,
440
443
StatementKind :: Assign ( box ( lhs_s, Rvalue :: Use ( Operand :: Constant ( s_c) ) ) ) ,
441
444
) if lhs_f == lhs_s && s_c. const_ . ty ( ) == f_ty => {
442
445
let Some ( f) = s_c. const_ . try_eval_scalar_int ( tcx, param_env) else {
0 commit comments