Skip to content

Commit 012626b

Browse files
committed
Only one caller of lower_match_tree was using the fake borrows
1 parent ea29d6a commit 012626b

File tree

1 file changed

+17
-31
lines changed
  • compiler/rustc_mir_build/src/build/matches

1 file changed

+17
-31
lines changed

compiler/rustc_mir_build/src/build/matches/mod.rs

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -315,12 +315,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
315315

316316
let match_start_span = span.shrink_to_lo().to(scrutinee_span);
317317

318-
let fake_borrow_temps = self.lower_match_tree(
318+
// The set of places that we are creating fake borrows of. If there are no match guards then
319+
// we don't need any fake borrows, so don't track them.
320+
let fake_borrow_temps: Vec<(Place<'tcx>, Local, FakeBorrowKind)> = if match_has_guard {
321+
util::collect_fake_borrows(self, &candidates, scrutinee_span, scrutinee_place.base())
322+
} else {
323+
Vec::new()
324+
};
325+
326+
self.lower_match_tree(
319327
block,
320328
scrutinee_span,
321329
&scrutinee_place,
322330
match_start_span,
323-
match_has_guard,
324331
&mut candidates,
325332
);
326333

@@ -377,30 +384,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
377384
///
378385
/// Modifies `candidates` to store the bindings and type ascriptions for
379386
/// that candidate.
380-
///
381-
/// Returns the places that need fake borrows because we bind or test them.
382387
fn lower_match_tree<'pat>(
383388
&mut self,
384389
block: BasicBlock,
385390
scrutinee_span: Span,
386391
scrutinee_place_builder: &PlaceBuilder<'tcx>,
387392
match_start_span: Span,
388-
match_has_guard: bool,
389393
candidates: &mut [&mut Candidate<'pat, 'tcx>],
390-
) -> Vec<(Place<'tcx>, Local, FakeBorrowKind)> {
391-
// The set of places that we are creating fake borrows of. If there are no match guards then
392-
// we don't need any fake borrows, so don't track them.
393-
let fake_borrows: Vec<(Place<'tcx>, Local, FakeBorrowKind)> = if match_has_guard {
394-
util::collect_fake_borrows(
395-
self,
396-
candidates,
397-
scrutinee_span,
398-
scrutinee_place_builder.base(),
399-
)
400-
} else {
401-
Vec::new()
402-
};
403-
394+
) {
404395
// See the doc comment on `match_candidates` for why we have an
405396
// otherwise block. Match checking will ensure this is actually
406397
// unreachable.
@@ -452,8 +443,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
452443
previous_candidate = Some(leaf_candidate);
453444
});
454445
}
455-
456-
fake_borrows
457446
}
458447

459448
/// Lower the bindings, guards and arm bodies of a `match` expression.
@@ -761,18 +750,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
761750
}
762751
}
763752

764-
let fake_borrow_temps = self.lower_match_tree(
753+
self.lower_match_tree(
765754
block,
766755
irrefutable_pat.span,
767756
&initializer,
768757
irrefutable_pat.span,
769-
false,
770758
&mut [&mut candidate],
771759
);
772760
self.bind_pattern(
773761
self.source_info(irrefutable_pat.span),
774762
candidate,
775-
fake_borrow_temps.as_slice(),
763+
&[],
776764
irrefutable_pat.span,
777765
None,
778766
false,
@@ -1995,12 +1983,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
19951983
let mut guard_candidate = Candidate::new(expr_place_builder.clone(), pat, false, self);
19961984
let mut otherwise_candidate =
19971985
Candidate::new(expr_place_builder.clone(), &wildcard, false, self);
1998-
let fake_borrow_temps = self.lower_match_tree(
1986+
self.lower_match_tree(
19991987
block,
20001988
pat.span,
20011989
&expr_place_builder,
20021990
pat.span,
2003-
false,
20041991
&mut [&mut guard_candidate, &mut otherwise_candidate],
20051992
);
20061993
let expr_place = expr_place_builder.try_to_place(self);
@@ -2015,7 +2002,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
20152002
let post_guard_block = self.bind_pattern(
20162003
self.source_info(pat.span),
20172004
guard_candidate,
2018-
fake_borrow_temps.as_slice(),
2005+
&[],
20192006
expr_span,
20202007
None,
20212008
false,
@@ -2490,19 +2477,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
24902477
let pat = Pat { ty: pattern.ty, span: else_block_span, kind: PatKind::Wild };
24912478
let mut wildcard = Candidate::new(scrutinee.clone(), &pat, false, this);
24922479
let mut candidate = Candidate::new(scrutinee.clone(), pattern, false, this);
2493-
let fake_borrow_temps = this.lower_match_tree(
2480+
this.lower_match_tree(
24942481
block,
24952482
initializer_span,
24962483
&scrutinee,
24972484
pattern.span,
2498-
false,
24992485
&mut [&mut candidate, &mut wildcard],
25002486
);
25012487
// This block is for the matching case
25022488
let matching = this.bind_pattern(
25032489
this.source_info(pattern.span),
25042490
candidate,
2505-
fake_borrow_temps.as_slice(),
2491+
&[],
25062492
initializer_span,
25072493
None,
25082494
true,
@@ -2511,7 +2497,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
25112497
let failure = this.bind_pattern(
25122498
this.source_info(else_block_span),
25132499
wildcard,
2514-
fake_borrow_temps.as_slice(),
2500+
&[],
25152501
initializer_span,
25162502
None,
25172503
true,

0 commit comments

Comments
 (0)