diff options
| author | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-07-05 14:52:18 +0200 |
|---|---|---|
| committer | Felix S. Klock II <pnkfelix@pnkfx.org> | 2017-08-16 16:08:28 +0200 |
| commit | 018784afc968f6aac9cf62b9339f07f1c06e45cb (patch) | |
| tree | fa53a30265ea752925d89f7d2b7b92e9f1c0a998 /src/librustc_data_structures | |
| parent | 869f05a5215242d90733bb6cb5455959f01effcd (diff) | |
| download | rust-018784afc968f6aac9cf62b9339f07f1c06e45cb.tar.gz rust-018784afc968f6aac9cf62b9339f07f1c06e45cb.zip | |
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.
Diffstat (limited to 'src/librustc_data_structures')
| -rw-r--r-- | src/librustc_data_structures/indexed_set.rs | 30 |
1 files changed, 30 insertions, 0 deletions
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<T: Idx> IdxSet<T> { pub fn each_bit<F>(&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<T> { + Elems { i: 0, set: self, universe_size: universe_size } + } +} + +pub struct Elems<'a, T: Idx> { i: usize, set: &'a IdxSet<T>, universe_size: usize } + +impl<'a, T: Idx> Iterator for Elems<'a, T> { + type Item = T; + fn next(&mut self) -> Option<T> { + 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<T: Idx, F>(words: &IdxSet<T>, max_bits: usize, mut f: F) where F: FnMut(T) { |
