Skip to content

Commit f0bbbd2

Browse files
authored
Rollup merge of #108902 - lcnr:do-while-sus, r=davidtwco,Nilstrieb
no more do while :<
2 parents fc2cb76 + a5258d1 commit f0bbbd2

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

0 commit comments

Comments
 (0)