Skip to content

Commit a5258d1

Browse files
committed
no more do while
1 parent 9b60e6c commit a5258d1

File tree

2 files changed

+23
-25
lines changed
  • compiler
    • rustc_mir_build/src/build/matches
    • rustc_mir_transform/src/coverage

2 files changed

+23
-25
lines changed

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

+3-5
Original file line numberDiff line numberDiff line change
@@ -581,8 +581,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
581581
// let PATTERN = ... might not even exist until we do the assignment.
582582
// so we set it here instead.
583583
if set_match_place {
584-
let mut candidate_ref = &candidate;
585-
while let Some(next) = {
584+
let mut next = Some(&candidate);
585+
while let Some(candidate_ref) = next.take() {
586586
for binding in &candidate_ref.bindings {
587587
let local = self.var_local_id(binding.var_id, OutsideGuard);
588588
// `try_to_place` may fail if it is unable to resolve the given
@@ -610,9 +610,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
610610
}
611611
// All of the subcandidates should bind the same locals, so we
612612
// only visit the first one.
613-
candidate_ref.subcandidates.get(0)
614-
} {
615-
candidate_ref = next;
613+
next = candidate_ref.subcandidates.get(0)
616614
}
617615
}
618616

compiler/rustc_mir_transform/src/coverage/graph.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -538,29 +538,29 @@ impl TraverseCoverageGraphWithLoops {
538538
"TraverseCoverageGraphWithLoops::next - context_stack: {:?}",
539539
self.context_stack.iter().rev().collect::<Vec<_>>()
540540
);
541-
while let Some(next_bcb) = {
542-
// Strip contexts with empty worklists from the top of the stack
543-
while self.context_stack.last().map_or(false, |context| context.worklist.is_empty()) {
541+
542+
while let Some(context) = self.context_stack.last_mut() {
543+
if let Some(next_bcb) = context.worklist.pop() {
544+
if !self.visited.insert(next_bcb) {
545+
debug!("Already visited: {:?}", next_bcb);
546+
continue;
547+
}
548+
debug!("Visiting {:?}", next_bcb);
549+
if self.backedges[next_bcb].len() > 0 {
550+
debug!("{:?} is a loop header! Start a new TraversalContext...", next_bcb);
551+
self.context_stack.push(TraversalContext {
552+
loop_backedges: Some((self.backedges[next_bcb].clone(), next_bcb)),
553+
worklist: Vec::new(),
554+
});
555+
}
556+
self.extend_worklist(basic_coverage_blocks, next_bcb);
557+
return Some(next_bcb);
558+
} else {
559+
// Strip contexts with empty worklists from the top of the stack
544560
self.context_stack.pop();
545561
}
546-
// Pop the next bcb off of the current context_stack. If none, all BCBs were visited.
547-
self.context_stack.last_mut().map_or(None, |context| context.worklist.pop())
548-
} {
549-
if !self.visited.insert(next_bcb) {
550-
debug!("Already visited: {:?}", next_bcb);
551-
continue;
552-
}
553-
debug!("Visiting {:?}", next_bcb);
554-
if self.backedges[next_bcb].len() > 0 {
555-
debug!("{:?} is a loop header! Start a new TraversalContext...", next_bcb);
556-
self.context_stack.push(TraversalContext {
557-
loop_backedges: Some((self.backedges[next_bcb].clone(), next_bcb)),
558-
worklist: Vec::new(),
559-
});
560-
}
561-
self.extend_worklist(basic_coverage_blocks, next_bcb);
562-
return Some(next_bcb);
563562
}
563+
564564
None
565565
}
566566

0 commit comments

Comments
 (0)