From 018784afc968f6aac9cf62b9339f07f1c06e45cb Mon Sep 17 00:00:00 2001 From: "Felix S. Klock II" Date: Wed, 5 Jul 2017 14:52:18 +0200 Subject: MIR based borrow check (opt-in). One can either use `-Z borrowck-mir` or add the `#[rustc_mir_borrowck]` attribute to opt into MIR based borrow checking. Note that regardless of whether one opts in or not, AST-based borrow check will still run as well. The errors emitted from AST-based borrow check will include a "(Ast)" suffix in their error message, while the errors emitted from MIR-based borrow check will include a "(Mir)" suffix. post-rebase: removed check for intra-statement mutual conflict; replaced with assertion checking that at most one borrow is generated per statement. post-rebase: removed dead code: `IdxSet::pairs` and supporting stuff. --- src/librustc_data_structures/indexed_set.rs | 30 +++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/librustc_data_structures') diff --git a/src/librustc_data_structures/indexed_set.rs b/src/librustc_data_structures/indexed_set.rs index 4189089e20d..9cb6806e9ad 100644 --- a/src/librustc_data_structures/indexed_set.rs +++ b/src/librustc_data_structures/indexed_set.rs @@ -159,6 +159,36 @@ impl IdxSet { pub fn each_bit(&self, max_bits: usize, f: F) where F: FnMut(T) { each_bit(self, max_bits, f) } + + /// Removes all elements from this set. + pub fn reset_to_empty(&mut self) { + for word in self.words_mut() { *word = 0; } + } + + pub fn elems(&self, universe_size: usize) -> Elems { + Elems { i: 0, set: self, universe_size: universe_size } + } +} + +pub struct Elems<'a, T: Idx> { i: usize, set: &'a IdxSet, universe_size: usize } + +impl<'a, T: Idx> Iterator for Elems<'a, T> { + type Item = T; + fn next(&mut self) -> Option { + if self.i >= self.universe_size { return None; } + let mut i = self.i; + loop { + if i >= self.universe_size { + self.i = i; // (mark iteration as complete.) + return None; + } + if self.set.contains(&T::new(i)) { + self.i = i + 1; // (next element to start at.) + return Some(T::new(i)); + } + i = i + 1; + } + } } fn each_bit(words: &IdxSet, max_bits: usize, mut f: F) where F: FnMut(T) { -- cgit 1.4.1-3-g733a5