Deduplicate operand creation between scalars, non-scalars and string patterns
This commit is contained in:
parent
633a3fe36d
commit
a9213c27ad
1 changed files with 11 additions and 8 deletions
|
@ -145,6 +145,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
let tcx = self.tcx;
|
let tcx = self.tcx;
|
||||||
let success_block = target_block(TestBranch::Success);
|
let success_block = target_block(TestBranch::Success);
|
||||||
let fail_block = target_block(TestBranch::Failure);
|
let fail_block = target_block(TestBranch::Failure);
|
||||||
|
|
||||||
|
let expect_ty = value.ty();
|
||||||
|
let expect = self.literal_operand(test.span, value);
|
||||||
if let ty::Adt(def, _) = ty.kind()
|
if let ty::Adt(def, _) = ty.kind()
|
||||||
&& tcx.is_lang_item(def.did(), LangItem::String)
|
&& tcx.is_lang_item(def.did(), LangItem::String)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +176,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
success_block,
|
success_block,
|
||||||
fail_block,
|
fail_block,
|
||||||
source_info,
|
source_info,
|
||||||
value,
|
expect,
|
||||||
|
expect_ty,
|
||||||
ref_str,
|
ref_str,
|
||||||
ref_str_ty,
|
ref_str_ty,
|
||||||
);
|
);
|
||||||
|
@ -185,13 +189,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
success_block,
|
success_block,
|
||||||
fail_block,
|
fail_block,
|
||||||
source_info,
|
source_info,
|
||||||
value,
|
expect,
|
||||||
|
expect_ty,
|
||||||
place,
|
place,
|
||||||
ty,
|
ty,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
assert_eq!(value.ty(), ty);
|
assert_eq!(expect_ty, ty);
|
||||||
let expect = self.literal_operand(test.span, value);
|
|
||||||
let val = Operand::Copy(place);
|
let val = Operand::Copy(place);
|
||||||
self.compare(
|
self.compare(
|
||||||
block,
|
block,
|
||||||
|
@ -371,12 +375,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
success_block: BasicBlock,
|
success_block: BasicBlock,
|
||||||
fail_block: BasicBlock,
|
fail_block: BasicBlock,
|
||||||
source_info: SourceInfo,
|
source_info: SourceInfo,
|
||||||
value: Const<'tcx>,
|
mut expect: Operand<'tcx>,
|
||||||
|
expect_ty: Ty<'tcx>,
|
||||||
mut val: Place<'tcx>,
|
mut val: Place<'tcx>,
|
||||||
mut ty: Ty<'tcx>,
|
mut ty: Ty<'tcx>,
|
||||||
) {
|
) {
|
||||||
let mut expect = self.literal_operand(source_info.span, value);
|
|
||||||
|
|
||||||
// If we're using `b"..."` as a pattern, we need to insert an
|
// If we're using `b"..."` as a pattern, we need to insert an
|
||||||
// unsizing coercion, as the byte string has the type `&[u8; N]`.
|
// unsizing coercion, as the byte string has the type `&[u8; N]`.
|
||||||
//
|
//
|
||||||
|
@ -391,7 +394,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
let opt_ref_ty = unsize(ty);
|
let opt_ref_ty = unsize(ty);
|
||||||
let opt_ref_test_ty = unsize(value.ty());
|
let opt_ref_test_ty = unsize(expect_ty);
|
||||||
match (opt_ref_ty, opt_ref_test_ty) {
|
match (opt_ref_ty, opt_ref_test_ty) {
|
||||||
// nothing to do, neither is an array
|
// nothing to do, neither is an array
|
||||||
(None, None) => {}
|
(None, None) => {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue