diff options
| author | Santiago Pastorino <spastorino@gmail.com> | 2017-09-27 14:29:11 -0300 |
|---|---|---|
| committer | Santiago Pastorino <spastorino@gmail.com> | 2017-10-04 23:50:53 -0300 |
| commit | f5cef21569115d41171114ec07bb144a3875afc3 (patch) | |
| tree | e2858b6a92b01dc779a3b6c38dc8fedf5c8896ac | |
| parent | 0c5de8633c8ea5d73606103db5049529c9b5d034 (diff) | |
| download | rust-f5cef21569115d41171114ec07bb144a3875afc3.tar.gz rust-f5cef21569115d41171114ec07bb144a3875afc3.zip | |
Convert regions to IndexVec
| -rw-r--r-- | src/librustc_mir/transform/nll/mod.rs | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/src/librustc_mir/transform/nll/mod.rs b/src/librustc_mir/transform/nll/mod.rs index 0ed0321a948..f06441f77e2 100644 --- a/src/librustc_mir/transform/nll/mod.rs +++ b/src/librustc_mir/transform/nll/mod.rs @@ -16,13 +16,14 @@ use rustc::mir::visit::{MutVisitor, Lookup}; use rustc::mir::transform::{MirPass, MirSource}; use rustc::infer::{self, InferCtxt}; use rustc::util::nodemap::FxHashSet; +use rustc_data_structures::indexed_vec::{IndexVec, Idx}; use syntax_pos::DUMMY_SP; use std::collections::HashMap; #[allow(dead_code)] struct NLLVisitor<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { lookup_map: HashMap<RegionVid, Lookup>, - regions: Vec<Region>, + regions: IndexVec<RegionIndex, Region>, infcx: InferCtxt<'a, 'gcx, 'tcx>, } @@ -31,7 +32,7 @@ impl<'a, 'gcx, 'tcx> NLLVisitor<'a, 'gcx, 'tcx> { NLLVisitor { infcx, lookup_map: HashMap::new(), - regions: vec![], + regions: IndexVec::new(), } } @@ -153,3 +154,19 @@ impl MirPass for NLL { struct Region { points: FxHashSet<Location>, } + +#[derive(Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd, Debug)] +pub struct RegionIndex(pub u32); + +impl Idx for RegionIndex { + #[inline] + fn new(idx: usize) -> Self { + assert!(idx <= ::std::u32::MAX as usize); + RegionIndex(idx as u32) + } + + #[inline] + fn index(self) -> usize { + self.0 as usize + } +} |
