Skip to content

Commit 7f6e160

Browse files
committed
Rename some index variables.
Now that all indices have type `usize`, it makes sense to be more consistent about their naming. This commit removes all uses of `i` in favour of `index`.
1 parent cf3a562 commit 7f6e160

File tree

1 file changed

+44
-44
lines changed
  • src/librustc_data_structures/obligation_forest

1 file changed

+44
-44
lines changed

src/librustc_data_structures/obligation_forest/mod.rs

+44-44
Original file line numberDiff line numberDiff line change
@@ -353,9 +353,9 @@ impl<O: ForestObligation> ObligationForest<O> {
353353
/// Converts all remaining obligations to the given error.
354354
pub fn to_errors<E: Clone>(&mut self, error: E) -> Vec<Error<O, E>> {
355355
let mut errors = vec![];
356-
for (i, node) in self.nodes.iter().enumerate() {
356+
for (index, node) in self.nodes.iter().enumerate() {
357357
if let NodeState::Pending = node.state.get() {
358-
let backtrace = self.error_at(i);
358+
let backtrace = self.error_at(index);
359359
errors.push(Error {
360360
error: error.clone(),
361361
backtrace,
@@ -399,10 +399,10 @@ impl<O: ForestObligation> ObligationForest<O> {
399399
let mut errors = vec![];
400400
let mut stalled = true;
401401

402-
for i in 0..self.nodes.len() {
403-
let node = &mut self.nodes[i];
402+
for index in 0..self.nodes.len() {
403+
let node = &mut self.nodes[index];
404404

405-
debug!("process_obligations: node {} == {:?}", i, node);
405+
debug!("process_obligations: node {} == {:?}", index, node);
406406

407407
// `processor.process_obligation` can modify the predicate within
408408
// `node.obligation`, and that predicate is the key used for
@@ -414,7 +414,7 @@ impl<O: ForestObligation> ObligationForest<O> {
414414
_ => continue
415415
};
416416

417-
debug!("process_obligations: node {} got result {:?}", i, result);
417+
debug!("process_obligations: node {} got result {:?}", index, result);
418418

419419
match result {
420420
ProcessResult::Unchanged => {
@@ -428,18 +428,18 @@ impl<O: ForestObligation> ObligationForest<O> {
428428
for child in children {
429429
let st = self.register_obligation_at(
430430
child,
431-
Some(i)
431+
Some(index)
432432
);
433433
if let Err(()) = st {
434434
// Error already reported - propagate it
435435
// to our node.
436-
self.error_at(i);
436+
self.error_at(index);
437437
}
438438
}
439439
}
440440
ProcessResult::Error(err) => {
441441
stalled = false;
442-
let backtrace = self.error_at(i);
442+
let backtrace = self.error_at(index);
443443
errors.push(Error {
444444
error: err,
445445
backtrace,
@@ -483,14 +483,14 @@ impl<O: ForestObligation> ObligationForest<O> {
483483

484484
debug!("process_cycles()");
485485

486-
for (i, node) in self.nodes.iter().enumerate() {
486+
for (index, node) in self.nodes.iter().enumerate() {
487487
// For rustc-benchmarks/inflate-0.1.0 this state test is extremely
488488
// hot and the state is almost always `Pending` or `Waiting`. It's
489489
// a win to handle the no-op cases immediately to avoid the cost of
490490
// the function call.
491491
match node.state.get() {
492492
NodeState::Waiting | NodeState::Pending | NodeState::Done | NodeState::Error => {},
493-
_ => self.find_cycles_from_node(&mut stack, processor, i),
493+
_ => self.find_cycles_from_node(&mut stack, processor, index),
494494
}
495495
}
496496

@@ -500,19 +500,19 @@ impl<O: ForestObligation> ObligationForest<O> {
500500
self.scratch.replace(stack);
501501
}
502502

503-
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, i: usize)
503+
fn find_cycles_from_node<P>(&self, stack: &mut Vec<usize>, processor: &mut P, index: usize)
504504
where P: ObligationProcessor<Obligation=O>
505505
{
506-
let node = &self.nodes[i];
506+
let node = &self.nodes[index];
507507
match node.state.get() {
508508
NodeState::OnDfsStack => {
509-
let i = stack.iter().rposition(|n| *n == i).unwrap();
510-
processor.process_backedge(stack[i..].iter().map(GetObligation(&self.nodes)),
509+
let index = stack.iter().rposition(|&n| n == index).unwrap();
510+
processor.process_backedge(stack[index..].iter().map(GetObligation(&self.nodes)),
511511
PhantomData);
512512
}
513513
NodeState::Success => {
514514
node.state.set(NodeState::OnDfsStack);
515-
stack.push(i);
515+
stack.push(index);
516516
for &index in node.dependents.iter() {
517517
self.find_cycles_from_node(stack, processor, index);
518518
}
@@ -531,28 +531,28 @@ impl<O: ForestObligation> ObligationForest<O> {
531531

532532
/// Returns a vector of obligations for `p` and all of its
533533
/// ancestors, putting them into the error state in the process.
534-
fn error_at(&self, mut i: usize) -> Vec<O> {
534+
fn error_at(&self, mut index: usize) -> Vec<O> {
535535
let mut error_stack = self.scratch.replace(vec![]);
536536
let mut trace = vec![];
537537

538538
loop {
539-
let node = &self.nodes[i];
539+
let node = &self.nodes[index];
540540
node.state.set(NodeState::Error);
541541
trace.push(node.obligation.clone());
542542
if node.has_parent {
543543
// The first dependent is the parent, which is treated
544544
// specially.
545545
error_stack.extend(node.dependents.iter().skip(1));
546-
i = node.dependents[0];
546+
index = node.dependents[0];
547547
} else {
548548
// No parent; treat all dependents non-specially.
549549
error_stack.extend(node.dependents.iter());
550550
break;
551551
}
552552
}
553553

554-
while let Some(i) = error_stack.pop() {
555-
let node = &self.nodes[i];
554+
while let Some(index) = error_stack.pop() {
555+
let node = &self.nodes[index];
556556
match node.state.get() {
557557
NodeState::Error => continue,
558558
_ => node.state.set(NodeState::Error),
@@ -568,8 +568,8 @@ impl<O: ForestObligation> ObligationForest<O> {
568568
// This always-inlined function is for the hot call site.
569569
#[inline(always)]
570570
fn inlined_mark_neighbors_as_waiting_from(&self, node: &Node<O>) {
571-
for &dependent in node.dependents.iter() {
572-
self.mark_as_waiting_from(&self.nodes[dependent]);
571+
for &index in node.dependents.iter() {
572+
self.mark_as_waiting_from(&self.nodes[index]);
573573
}
574574
}
575575

@@ -622,16 +622,16 @@ impl<O: ForestObligation> ObligationForest<O> {
622622
// Now move all popped nodes to the end. Try to keep the order.
623623
//
624624
// LOOP INVARIANT:
625-
// self.nodes[0..i - dead_nodes] are the first remaining nodes
626-
// self.nodes[i - dead_nodes..i] are all dead
627-
// self.nodes[i..] are unchanged
628-
for i in 0..self.nodes.len() {
629-
let node = &self.nodes[i];
625+
// self.nodes[0..index - dead_nodes] are the first remaining nodes
626+
// self.nodes[index - dead_nodes..index] are all dead
627+
// self.nodes[index..] are unchanged
628+
for index in 0..self.nodes.len() {
629+
let node = &self.nodes[index];
630630
match node.state.get() {
631631
NodeState::Pending | NodeState::Waiting => {
632632
if dead_nodes > 0 {
633-
self.nodes.swap(i, i - dead_nodes);
634-
node_rewrites[i] -= dead_nodes;
633+
self.nodes.swap(index, index - dead_nodes);
634+
node_rewrites[index] -= dead_nodes;
635635
}
636636
}
637637
NodeState::Done => {
@@ -646,17 +646,17 @@ impl<O: ForestObligation> ObligationForest<O> {
646646
} else {
647647
self.done_cache.insert(node.obligation.as_predicate().clone());
648648
}
649-
node_rewrites[i] = nodes_len;
649+
node_rewrites[index] = nodes_len;
650650
dead_nodes += 1;
651651
}
652652
NodeState::Error => {
653653
// We *intentionally* remove the node from the cache at this point. Otherwise
654654
// tests must come up with a different type on every type error they
655655
// check against.
656656
self.waiting_cache.remove(node.obligation.as_predicate());
657-
node_rewrites[i] = nodes_len;
657+
node_rewrites[index] = nodes_len;
658658
dead_nodes += 1;
659-
self.insert_into_error_cache(i);
659+
self.insert_into_error_cache(index);
660660
}
661661
NodeState::OnDfsStack | NodeState::Success => unreachable!()
662662
}
@@ -697,30 +697,30 @@ impl<O: ForestObligation> ObligationForest<O> {
697697
let nodes_len = node_rewrites.len();
698698

699699
for node in &mut self.nodes {
700-
let mut i = 0;
701-
while i < node.dependents.len() {
702-
let new_i = node_rewrites[node.dependents[i]];
703-
if new_i >= nodes_len {
704-
node.dependents.swap_remove(i);
705-
if i == 0 && node.has_parent {
700+
let mut index = 0;
701+
while index < node.dependents.len() {
702+
let new_index = node_rewrites[node.dependents[index]];
703+
if new_index >= nodes_len {
704+
node.dependents.swap_remove(index);
705+
if index == 0 && node.has_parent {
706706
// We just removed the parent.
707707
node.has_parent = false;
708708
}
709709
} else {
710-
node.dependents[i] = new_i;
711-
i += 1;
710+
node.dependents[index] = new_index;
711+
index += 1;
712712
}
713713
}
714714
}
715715

716716
// This updating of `self.waiting_cache` is necessary because the
717717
// removal of nodes within `compress` can fail. See above.
718718
self.waiting_cache.retain(|_predicate, index| {
719-
let new_i = node_rewrites[*index];
720-
if new_i >= nodes_len {
719+
let new_index = node_rewrites[*index];
720+
if new_index >= nodes_len {
721721
false
722722
} else {
723-
*index = new_i;
723+
*index = new_index;
724724
true
725725
}
726726
});

0 commit comments

Comments
 (0)