Use clearer variable names in equality-test lowering
This commit is contained in:
parent
fcd630976c
commit
91e169b1c9
1 changed files with 28 additions and 22 deletions
|
|
@ -141,17 +141,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
self.cfg.terminate(block, self.source_info(match_start_span), terminator);
|
||||
}
|
||||
|
||||
TestKind::Eq { value, mut cast_ty } => {
|
||||
TestKind::Eq { value, cast_ty: pat_ty } => {
|
||||
let tcx = self.tcx;
|
||||
let success_block = target_block(TestBranch::Success);
|
||||
let fail_block = target_block(TestBranch::Failure);
|
||||
|
||||
let mut expect_ty = value.ty;
|
||||
let mut expect = self.literal_operand(test.span, Const::from_ty_value(tcx, value));
|
||||
let mut expected_value_ty = value.ty;
|
||||
let mut expected_value_operand =
|
||||
self.literal_operand(test.span, Const::from_ty_value(tcx, value));
|
||||
|
||||
let mut place = place;
|
||||
let mut actual_value_ty = pat_ty;
|
||||
let mut actual_value_place = place;
|
||||
|
||||
match cast_ty.kind() {
|
||||
match pat_ty.kind() {
|
||||
ty::Str => {
|
||||
// String literal patterns may have type `str` if `deref_patterns` is
|
||||
// enabled, in order to allow `deref!("..."): String`. In this case, `value`
|
||||
|
|
@ -172,11 +174,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
ref_place,
|
||||
Rvalue::Ref(re_erased, BorrowKind::Shared, place),
|
||||
);
|
||||
place = ref_place;
|
||||
cast_ty = ref_str_ty;
|
||||
actual_value_place = ref_place;
|
||||
actual_value_ty = ref_str_ty;
|
||||
}
|
||||
&ty::Pat(base, _) => {
|
||||
assert_eq!(cast_ty, value.ty);
|
||||
assert_eq!(pat_ty, value.ty);
|
||||
assert!(base.is_trivially_pure_clone_copy());
|
||||
|
||||
let transmuted_place = self.temp(base, test.span);
|
||||
|
|
@ -184,7 +186,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
self.source_info(scrutinee_span),
|
||||
transmuted_place,
|
||||
Rvalue::Cast(CastKind::Transmute, Operand::Copy(place), base),
|
||||
Rvalue::Cast(
|
||||
CastKind::Transmute,
|
||||
Operand::Copy(actual_value_place),
|
||||
base,
|
||||
),
|
||||
);
|
||||
|
||||
let transmuted_expect = self.temp(base, test.span);
|
||||
|
|
@ -192,19 +198,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
block,
|
||||
self.source_info(test.span),
|
||||
transmuted_expect,
|
||||
Rvalue::Cast(CastKind::Transmute, expect, base),
|
||||
Rvalue::Cast(CastKind::Transmute, expected_value_operand, base),
|
||||
);
|
||||
|
||||
place = transmuted_place;
|
||||
expect = Operand::Copy(transmuted_expect);
|
||||
cast_ty = base;
|
||||
expect_ty = base;
|
||||
actual_value_place = transmuted_place;
|
||||
actual_value_ty = base;
|
||||
expected_value_operand = Operand::Copy(transmuted_expect);
|
||||
expected_value_ty = base;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
assert_eq!(expect_ty, cast_ty);
|
||||
if !cast_ty.is_scalar() {
|
||||
assert_eq!(expected_value_ty, actual_value_ty);
|
||||
if !actual_value_ty.is_scalar() {
|
||||
// Use `PartialEq::eq` instead of `BinOp::Eq`
|
||||
// (the binop can only handle primitives)
|
||||
// Make sure that we do *not* call any user-defined code here.
|
||||
|
|
@ -212,12 +218,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
// comparison defined in `core`.
|
||||
// (Interestingly this means that exhaustiveness analysis relies, for soundness,
|
||||
// on the `PartialEq` impl for `str` to b correct!)
|
||||
match *cast_ty.kind() {
|
||||
match *actual_value_ty.kind() {
|
||||
ty::Ref(_, deref_ty, _) if deref_ty == self.tcx.types.str_ => {}
|
||||
_ => {
|
||||
span_bug!(
|
||||
source_info.span,
|
||||
"invalid type for non-scalar compare: {cast_ty}"
|
||||
"invalid type for non-scalar compare: {actual_value_ty}"
|
||||
)
|
||||
}
|
||||
};
|
||||
|
|
@ -226,8 +232,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
success_block,
|
||||
fail_block,
|
||||
source_info,
|
||||
expect,
|
||||
Operand::Copy(place),
|
||||
expected_value_operand,
|
||||
Operand::Copy(actual_value_place),
|
||||
);
|
||||
} else {
|
||||
self.compare(
|
||||
|
|
@ -236,8 +242,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
|||
fail_block,
|
||||
source_info,
|
||||
BinOp::Eq,
|
||||
expect,
|
||||
Operand::Copy(place),
|
||||
expected_value_operand,
|
||||
Operand::Copy(actual_value_place),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue