diff options
| author | DianQK <dianqk@dianqk.net> | 2024-03-10 22:07:41 +0800 |
|---|---|---|
| committer | DianQK <dianqk@dianqk.net> | 2024-04-08 19:07:53 +0800 |
| commit | 032bb742ab537ac41ce5428b9c344a8c348bd2c9 (patch) | |
| tree | bc1c6defeb08de4445b86294f26a7c24a5a3cb9f | |
| parent | 254289a16e318bbbbecadb05c14abbc07f16d2b4 (diff) | |
| download | rust-032bb742ab537ac41ce5428b9c344a8c348bd2c9.tar.gz rust-032bb742ab537ac41ce5428b9c344a8c348bd2c9.zip | |
Add comments for `CompareType`
| -rw-r--r-- | compiler/rustc_mir_transform/src/match_branches.rs | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/compiler/rustc_mir_transform/src/match_branches.rs b/compiler/rustc_mir_transform/src/match_branches.rs index e9203043769..2b6589100c8 100644 --- a/compiler/rustc_mir_transform/src/match_branches.rs +++ b/compiler/rustc_mir_transform/src/match_branches.rs @@ -269,9 +269,12 @@ struct SimplifyToExp { #[derive(Clone, Copy)] enum CompareType<'tcx, 'a> { + /// Identical statements. Same(&'a StatementKind<'tcx>), + /// Assignment statements have the same value. Eq(&'a Place<'tcx>, Ty<'tcx>, ScalarInt), - Discr(&'a Place<'tcx>, Ty<'tcx>, bool), + /// Enum variant comparison type. + Discr { place: &'a Place<'tcx>, ty: Ty<'tcx>, is_signed: bool }, } enum TransfromType { @@ -285,7 +288,7 @@ impl From<CompareType<'_, '_>> for TransfromType { match compare_type { CompareType::Same(_) => TransfromType::Same, CompareType::Eq(_, _, _) => TransfromType::Eq, - CompareType::Discr(_, _, _) => TransfromType::Discr, + CompareType::Discr { .. } => TransfromType::Discr, } } } @@ -402,11 +405,11 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp { && Some(s) == ScalarInt::try_from_uint(second_val, s.size())) => { - CompareType::Discr( - lhs_f, - f_c.const_.ty(), - f_c.const_.ty().is_signed() || discr_ty.is_signed(), - ) + CompareType::Discr { + place: lhs_f, + ty: f_c.const_.ty(), + is_signed: f_c.const_.ty().is_signed() || discr_ty.is_signed(), + } } _ => { return false; @@ -436,7 +439,7 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp { && s_c.const_.ty() == f_ty && s_c.const_.try_eval_scalar_int(tcx, param_env) == Some(val) => {} ( - CompareType::Discr(lhs_f, f_ty, is_signed), + CompareType::Discr { place: lhs_f, ty: f_ty, is_signed }, StatementKind::Assign(box (lhs_s, Rvalue::Use(Operand::Constant(s_c)))), ) if lhs_f == lhs_s && s_c.const_.ty() == f_ty => { let Some(f) = s_c.const_.try_eval_scalar_int(tcx, param_env) else { |
