Skip to content

Commit 032bb74

Browse files
committed
Add comments for CompareType
1 parent 254289a commit 032bb74

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

compiler/rustc_mir_transform/src/match_branches.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -269,9 +269,12 @@ struct SimplifyToExp {
269269

270270
#[derive(Clone, Copy)]
271271
enum CompareType<'tcx, 'a> {
272+
/// Identical statements.
272273
Same(&'a StatementKind<'tcx>),
274+
/// Assignment statements have the same value.
273275
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 },
275278
}
276279

277280
enum TransfromType {
@@ -285,7 +288,7 @@ impl From<CompareType<'_, '_>> for TransfromType {
285288
match compare_type {
286289
CompareType::Same(_) => TransfromType::Same,
287290
CompareType::Eq(_, _, _) => TransfromType::Eq,
288-
CompareType::Discr(_, _, _) => TransfromType::Discr,
291+
CompareType::Discr { .. } => TransfromType::Discr,
289292
}
290293
}
291294
}
@@ -402,11 +405,11 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
402405
&& Some(s)
403406
== ScalarInt::try_from_uint(second_val, s.size())) =>
404407
{
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+
}
410413
}
411414
_ => {
412415
return false;
@@ -436,7 +439,7 @@ impl<'tcx> SimplifyMatch<'tcx> for SimplifyToExp {
436439
&& s_c.const_.ty() == f_ty
437440
&& s_c.const_.try_eval_scalar_int(tcx, param_env) == Some(val) => {}
438441
(
439-
CompareType::Discr(lhs_f, f_ty, is_signed),
442+
CompareType::Discr { place: lhs_f, ty: f_ty, is_signed },
440443
StatementKind::Assign(box (lhs_s, Rvalue::Use(Operand::Constant(s_c)))),
441444
) if lhs_f == lhs_s && s_c.const_.ty() == f_ty => {
442445
let Some(f) = s_c.const_.try_eval_scalar_int(tcx, param_env) else {

0 commit comments

Comments
 (0)