Skip to content

Commit a9213c2

Browse files
committed
Deduplicate operand creation between scalars, non-scalars and string patterns
1 parent 633a3fe commit a9213c2

File tree

1 file changed

+11
-8
lines changed
  • compiler/rustc_mir_build/src/builder/matches

1 file changed

+11
-8
lines changed

compiler/rustc_mir_build/src/builder/matches/test.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
145145
let tcx = self.tcx;
146146
let success_block = target_block(TestBranch::Success);
147147
let fail_block = target_block(TestBranch::Failure);
148+
149+
let expect_ty = value.ty();
150+
let expect = self.literal_operand(test.span, value);
148151
if let ty::Adt(def, _) = ty.kind()
149152
&& tcx.is_lang_item(def.did(), LangItem::String)
150153
{
@@ -173,7 +176,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
173176
success_block,
174177
fail_block,
175178
source_info,
176-
value,
179+
expect,
180+
expect_ty,
177181
ref_str,
178182
ref_str_ty,
179183
);
@@ -185,13 +189,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
185189
success_block,
186190
fail_block,
187191
source_info,
188-
value,
192+
expect,
193+
expect_ty,
189194
place,
190195
ty,
191196
);
192197
} else {
193-
assert_eq!(value.ty(), ty);
194-
let expect = self.literal_operand(test.span, value);
198+
assert_eq!(expect_ty, ty);
195199
let val = Operand::Copy(place);
196200
self.compare(
197201
block,
@@ -371,12 +375,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
371375
success_block: BasicBlock,
372376
fail_block: BasicBlock,
373377
source_info: SourceInfo,
374-
value: Const<'tcx>,
378+
mut expect: Operand<'tcx>,
379+
expect_ty: Ty<'tcx>,
375380
mut val: Place<'tcx>,
376381
mut ty: Ty<'tcx>,
377382
) {
378-
let mut expect = self.literal_operand(source_info.span, value);
379-
380383
// If we're using `b"..."` as a pattern, we need to insert an
381384
// unsizing coercion, as the byte string has the type `&[u8; N]`.
382385
//
@@ -391,7 +394,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
391394
_ => None,
392395
};
393396
let opt_ref_ty = unsize(ty);
394-
let opt_ref_test_ty = unsize(value.ty());
397+
let opt_ref_test_ty = unsize(expect_ty);
395398
match (opt_ref_ty, opt_ref_test_ty) {
396399
// nothing to do, neither is an array
397400
(None, None) => {}

0 commit comments

Comments
 (0)