Skip to content

Commit 1936e44

Browse files
committed
Factor out repeated self.nodes[i] expressions.
1 parent 43c0d2c commit 1936e44

File tree

1 file changed

+14
-15
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+14
-15
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ impl<O: ForestObligation> ObligationForest<O> {
386386

387387
fn insert_into_error_cache(&mut self, node_index: usize) {
388388
let node = &self.nodes[node_index];
389-
390389
self.error_cache
391390
.entry(node.obligation_tree_id)
392391
.or_default()
@@ -407,11 +406,12 @@ impl<O: ForestObligation> ObligationForest<O> {
407406
let mut stalled = true;
408407

409408
for i in 0..self.nodes.len() {
410-
debug!("process_obligations: node {} == {:?}", i, self.nodes[i]);
409+
let node = &mut self.nodes[i];
410+
411+
debug!("process_obligations: node {} == {:?}", i, node);
411412

412-
let result = match self.nodes[i] {
413-
Node { ref state, ref mut obligation, .. } if state.get() == NodeState::Pending =>
414-
processor.process_obligation(obligation),
413+
let result = match node.state.get() {
414+
NodeState::Pending => processor.process_obligation(&mut node.obligation),
415415
_ => continue
416416
};
417417

@@ -424,7 +424,7 @@ impl<O: ForestObligation> ObligationForest<O> {
424424
ProcessResult::Changed(children) => {
425425
// We are not (yet) stalled.
426426
stalled = false;
427-
self.nodes[i].state.set(NodeState::Success);
427+
node.state.set(NodeState::Success);
428428

429429
for child in children {
430430
let st = self.register_obligation_at(
@@ -491,8 +491,7 @@ impl<O: ForestObligation> ObligationForest<O> {
491491
// hot and the state is almost always `Pending` or `Waiting`. It's
492492
// a win to handle the no-op cases immediately to avoid the cost of
493493
// the function call.
494-
let state = self.nodes[i].state.get();
495-
match state {
494+
match self.nodes[i].state.get() {
496495
NodeState::Waiting | NodeState::Pending | NodeState::Done | NodeState::Error => {},
497496
_ => self.find_cycles_from_node(&mut stack, processor, i),
498497
}
@@ -508,8 +507,7 @@ impl<O: ForestObligation> ObligationForest<O> {
508507
where P: ObligationProcessor<Obligation=O>
509508
{
510509
let node = &self.nodes[i];
511-
let state = node.state.get();
512-
match state {
510+
match node.state.get() {
513511
NodeState::OnDfsStack => {
514512
let i = stack.iter().rposition(|n| *n == i).unwrap();
515513
processor.process_backedge(stack[i..].iter().map(GetObligation(&self.nodes)),
@@ -557,7 +555,7 @@ impl<O: ForestObligation> ObligationForest<O> {
557555
let node = &self.nodes[i];
558556
match node.state.get() {
559557
NodeState::Error => continue,
560-
_ => self.nodes[i].state.set(NodeState::Error),
558+
_ => node.state.set(NodeState::Error),
561559
}
562560

563561
error_stack.extend(
@@ -630,7 +628,8 @@ impl<O: ForestObligation> ObligationForest<O> {
630628
// self.nodes[i - dead_nodes..i] are all dead
631629
// self.nodes[i..] are unchanged
632630
for i in 0..self.nodes.len() {
633-
match self.nodes[i].state.get() {
631+
let node = &self.nodes[i];
632+
match node.state.get() {
634633
NodeState::Pending | NodeState::Waiting => {
635634
if dead_nodes > 0 {
636635
self.nodes.swap(i, i - dead_nodes);
@@ -640,11 +639,11 @@ impl<O: ForestObligation> ObligationForest<O> {
640639
NodeState::Done => {
641640
// Avoid cloning the key (predicate) in case it exists in the waiting cache
642641
if let Some((predicate, _)) = self.waiting_cache
643-
.remove_entry(self.nodes[i].obligation.as_predicate())
642+
.remove_entry(node.obligation.as_predicate())
644643
{
645644
self.done_cache.insert(predicate);
646645
} else {
647-
self.done_cache.insert(self.nodes[i].obligation.as_predicate().clone());
646+
self.done_cache.insert(node.obligation.as_predicate().clone());
648647
}
649648
node_rewrites[i] = nodes_len;
650649
dead_nodes += 1;
@@ -653,7 +652,7 @@ impl<O: ForestObligation> ObligationForest<O> {
653652
// We *intentionally* remove the node from the cache at this point. Otherwise
654653
// tests must come up with a different type on every type error they
655654
// check against.
656-
self.waiting_cache.remove(self.nodes[i].obligation.as_predicate());
655+
self.waiting_cache.remove(node.obligation.as_predicate());
657656
node_rewrites[i] = nodes_len;
658657
dead_nodes += 1;
659658
self.insert_into_error_cache(i);

0 commit comments

Comments
 (0)