-use rustc::mir::{BasicBlock, Location, Body};
-use rustc_data_structures::indexed_vec::{Idx, IndexVec};
+use rustc::mir::{BasicBlock, Body, Location};
+use rustc_index::vec::{Idx, IndexVec};
/// Maps between a MIR Location, which identifies a particular
/// statement within a basic block, to a "rich location", which
statements_before_block: IndexVec<BasicBlock, usize>,
}
-newtype_index! {
+rustc_index::newtype_index! {
pub struct LocationIndex {
DEBUG_FORMAT = "LocationIndex({})"
}
impl LocationTable {
crate fn new(body: &Body<'_>) -> Self {
let mut num_points = 0;
- let statements_before_block = body.basic_blocks()
+ let statements_before_block = body
+ .basic_blocks()
.iter()
.map(|block_data| {
let v = num_points;
})
.collect();
- debug!(
- "LocationTable(statements_before_block={:#?})",
- statements_before_block
- );
+ debug!("LocationTable(statements_before_block={:#?})", statements_before_block);
debug!("LocationTable: num_points={:#?}", num_points);
- Self {
- num_points,
- statements_before_block,
- }
+ Self { num_points, statements_before_block }
}
crate fn all_points(&self) -> impl Iterator<Item = LocationIndex> {
}
crate fn start_index(&self, location: Location) -> LocationIndex {
- let Location {
- block,
- statement_index,
- } = location;
+ let Location { block, statement_index } = location;
let start_index = self.statements_before_block[block];
LocationIndex::new(start_index + statement_index * 2)
}
crate fn mid_index(&self, location: Location) -> LocationIndex {
- let Location {
- block,
- statement_index,
- } = location;
+ let Location { block, statement_index } = location;
let start_index = self.statements_before_block[block];
LocationIndex::new(start_index + statement_index * 2 + 1)
}
// the last point where the "first index" (0, 10, or 20)
// was less than the statement index (22). In our case, this will
// be (BB2, 20).
- let (block, &first_index) = self.statements_before_block
+ let (block, &first_index) = self
+ .statements_before_block
.iter_enumerated()
.filter(|(_, first_index)| **first_index <= point_index)
.last()