Skip to content

Commit a6c107c

Browse files
committed
Convert regions to IndexVec
1 parent d00d4e9 commit a6c107c

File tree

1 file changed

+19
-2
lines changed
  • src/librustc_mir/transform

1 file changed

+19
-2
lines changed

src/librustc_mir/transform/nll.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@ use rustc::mir::visit::{MutVisitor, Lookup};
1616
use rustc::mir::transform::{MirPass, MirSource};
1717
use rustc::infer::{self, InferCtxt};
1818
use rustc::util::nodemap::FxHashSet;
19+
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
1920
use syntax_pos::DUMMY_SP;
2021
use std::collections::HashMap;
2122

2223
#[allow(dead_code)]
2324
struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
2425
lookup_map: HashMap<RegionVid, Lookup>,
25-
regions: Vec<Region>,
26+
regions: IndexVec<RegionIndex, Region>,
2627
infcx: InferCtxt<'a, 'gcx, 'tcx>,
2728
}
2829

@@ -31,7 +32,7 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> {
3132
NLLVisitor {
3233
infcx,
3334
lookup_map: HashMap::new(),
34-
regions: vec![],
35+
regions: IndexVec::new(),
3536
}
3637
}
3738

@@ -153,3 +154,19 @@ impl MirPass for NLL {
153154
struct Region {
154155
points: FxHashSet<Location>,
155156
}
157+
158+
#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)]
159+
pub struct RegionIndex(pub u32);
160+
161+
impl Idx for RegionIndex {
162+
#[inline]
163+
fn new(idx: usize) -> Self {
164+
assert!(idx <= ::std::u32::MAX as usize);
165+
RegionIndex(idx as u32)
166+
}
167+
168+
#[inline]
169+
fn index(self) -> usize {
170+
self.0 as usize
171+
}
172+
}

0 commit comments

Comments
 (0)