Skip to content

Commit ae1e1bd

Browse files
committed
No need to pass fake_borrows everywhere now
1 parent ca5edfa commit ae1e1bd

File tree

1 file changed

+8
-45
lines changed
  • compiler/rustc_mir_build/src/build/matches

1 file changed

+8
-45
lines changed

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

+8-45
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
315315
// The set of places that we are creating fake borrows of. If there are
316316
// no match guards then we don't need any fake borrows, so don't track
317317
// them.
318-
let mut fake_borrows = match_has_guard
318+
let fake_borrows = match_has_guard
319319
.then(|| util::FakeBorrowCollector::collect_fake_borrows(self, candidates));
320320

321321
let otherwise_block = self.cfg.start_new_block();
322322

323323
// This will generate code to test scrutinee_place and
324324
// branch to the appropriate arm block
325-
self.match_candidates(
326-
match_start_span,
327-
scrutinee_span,
328-
block,
329-
otherwise_block,
330-
candidates,
331-
&mut fake_borrows,
332-
);
325+
self.match_candidates(match_start_span, scrutinee_span, block, otherwise_block, candidates);
333326

334327
// See the doc comment on `match_candidates` for why we may have an
335328
// otherwise block. Match checking will ensure this is actually
@@ -1236,15 +1229,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12361229
///
12371230
/// Note how we test `x` twice. This is the tradeoff of backtracking automata: we prefer smaller
12381231
/// code size at the expense of non-optimal code paths.
1239-
#[instrument(skip(self, fake_borrows), level = "debug")]
1232+
#[instrument(skip(self), level = "debug")]
12401233
fn match_candidates<'pat>(
12411234
&mut self,
12421235
span: Span,
12431236
scrutinee_span: Span,
12441237
start_block: BasicBlock,
12451238
otherwise_block: BasicBlock,
12461239
candidates: &mut [&mut Candidate<'pat, 'tcx>],
1247-
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
12481240
) {
12491241
let mut split_or_candidate = false;
12501242
for candidate in &mut *candidates {
@@ -1281,7 +1273,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12811273
start_block,
12821274
otherwise_block,
12831275
&mut *new_candidates,
1284-
fake_borrows,
12851276
);
12861277
} else {
12871278
self.match_simplified_candidates(
@@ -1290,7 +1281,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
12901281
start_block,
12911282
otherwise_block,
12921283
candidates,
1293-
fake_borrows,
12941284
);
12951285
}
12961286
});
@@ -1303,7 +1293,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13031293
mut start_block: BasicBlock,
13041294
otherwise_block: BasicBlock,
13051295
candidates: &mut [&mut Candidate<'_, 'tcx>],
1306-
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
13071296
) {
13081297
match candidates {
13091298
[] => {
@@ -1315,14 +1304,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13151304
[first, remaining @ ..] if first.match_pairs.is_empty() => {
13161305
// The first candidate has satisfied all its match pairs; we link it up and continue
13171306
// with the remaining candidates.
1318-
start_block = self.select_matched_candidate(first, start_block, fake_borrows);
1307+
start_block = self.select_matched_candidate(first, start_block);
13191308
self.match_simplified_candidates(
13201309
span,
13211310
scrutinee_span,
13221311
start_block,
13231312
otherwise_block,
13241313
remaining,
1325-
fake_borrows,
13261314
)
13271315
}
13281316
candidates => {
@@ -1333,7 +1321,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13331321
candidates,
13341322
start_block,
13351323
otherwise_block,
1336-
fake_borrows,
13371324
);
13381325
}
13391326
}
@@ -1368,7 +1355,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
13681355
&mut self,
13691356
candidate: &mut Candidate<'_, 'tcx>,
13701357
start_block: BasicBlock,
1371-
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
13721358
) -> BasicBlock {
13731359
assert!(candidate.otherwise_block.is_none());
13741360
assert!(candidate.pre_binding_block.is_none());
@@ -1444,19 +1430,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14441430
candidates: &mut [&mut Candidate<'_, 'tcx>],
14451431
start_block: BasicBlock,
14461432
otherwise_block: BasicBlock,
1447-
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
14481433
) {
14491434
let (first_candidate, remaining_candidates) = candidates.split_first_mut().unwrap();
14501435
assert!(first_candidate.subcandidates.is_empty());
14511436
if !matches!(first_candidate.match_pairs[0].test_case, TestCase::Or { .. }) {
1452-
self.test_candidates(
1453-
span,
1454-
scrutinee_span,
1455-
candidates,
1456-
start_block,
1457-
otherwise_block,
1458-
fake_borrows,
1459-
);
1437+
self.test_candidates(span, scrutinee_span, candidates, start_block, otherwise_block);
14601438
return;
14611439
}
14621440

@@ -1467,14 +1445,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14671445
let remainder_start = self.cfg.start_new_block();
14681446
let or_span = first_match_pair.pattern.span;
14691447
// Test the alternatives of this or-pattern.
1470-
self.test_or_pattern(
1471-
first_candidate,
1472-
start_block,
1473-
remainder_start,
1474-
pats,
1475-
or_span,
1476-
fake_borrows,
1477-
);
1448+
self.test_or_pattern(first_candidate, start_block, remainder_start, pats, or_span);
14781449

14791450
if !remaining_match_pairs.is_empty() {
14801451
// If more match pairs remain, test them after each subcandidate.
@@ -1495,7 +1466,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
14951466
&mut [leaf_candidate],
14961467
or_start,
14971468
or_otherwise,
1498-
fake_borrows,
14991469
);
15001470
});
15011471
}
@@ -1507,12 +1477,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15071477
remainder_start,
15081478
otherwise_block,
15091479
remaining_candidates,
1510-
fake_borrows,
15111480
);
15121481
}
15131482

15141483
#[instrument(
1515-
skip(self, start_block, otherwise_block, or_span, fake_borrows, candidate, pats),
1484+
skip(self, start_block, otherwise_block, or_span, candidate, pats),
15161485
level = "debug"
15171486
)]
15181487
fn test_or_pattern<'pat>(
@@ -1522,7 +1491,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15221491
otherwise_block: BasicBlock,
15231492
pats: &[FlatPat<'pat, 'tcx>],
15241493
or_span: Span,
1525-
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
15261494
) {
15271495
debug!("candidate={:#?}\npats={:#?}", candidate, pats);
15281496
let mut or_candidates: Vec<_> = pats
@@ -1537,7 +1505,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15371505
start_block,
15381506
otherwise_block,
15391507
&mut or_candidate_refs,
1540-
fake_borrows,
15411508
);
15421509
candidate.subcandidates = or_candidates;
15431510
self.merge_trivial_subcandidates(candidate, self.source_info(or_span));
@@ -1597,7 +1564,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
15971564
fn pick_test(
15981565
&mut self,
15991566
candidates: &mut [&mut Candidate<'_, 'tcx>],
1600-
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
16011567
) -> (PlaceBuilder<'tcx>, Test<'tcx>) {
16021568
// Extract the match-pair from the highest priority candidate
16031569
let match_pair = &candidates.first().unwrap().match_pairs[0];
@@ -1799,10 +1765,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
17991765
candidates: &'b mut [&'c mut Candidate<'pat, 'tcx>],
18001766
start_block: BasicBlock,
18011767
otherwise_block: BasicBlock,
1802-
fake_borrows: &mut Option<FxIndexSet<Place<'tcx>>>,
18031768
) {
18041769
// Extract the match-pair from the highest priority candidate and build a test from it.
1805-
let (match_place, test) = self.pick_test(candidates, fake_borrows);
1770+
let (match_place, test) = self.pick_test(candidates);
18061771

18071772
// For each of the N possible test outcomes, build the vector of candidates that applies if
18081773
// the test has that particular outcome.
@@ -1819,7 +1784,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18191784
remainder_start,
18201785
otherwise_block,
18211786
remaining_candidates,
1822-
fake_borrows,
18231787
);
18241788
remainder_start
18251789
} else {
@@ -1841,7 +1805,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
18411805
candidate_start,
18421806
remainder_start,
18431807
&mut *candidates,
1844-
fake_borrows,
18451808
);
18461809
candidate_start
18471810
} else {

0 commit comments

Comments
 (0)