From 32dd592d36c731fd3bbd0cda8040d33b44a90f4b Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Sat, 3 Jan 2015 10:40:10 -0500 Subject: [PATCH] collections: fix fallout --- src/libcollections/bit.rs | 17 +++++++++++++++++ src/libcollections/btree/map.rs | 28 ++++++++++++++++++++++++++++ src/libcollections/ring_buf.rs | 26 ++++++++++++++++++++++++++ src/libcollections/vec.rs | 25 +++++++++++++++++++++++++ src/libcollections/vec_map.rs | 25 +++++++++++++++++++++++++ 5 files changed, 121 insertions(+) diff --git a/src/libcollections/bit.rs b/src/libcollections/bit.rs index 5c52223bccd..9674885c857 100644 --- a/src/libcollections/bit.rs +++ b/src/libcollections/bit.rs @@ -164,6 +164,8 @@ pub struct Bitv { nbits: uint } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] // FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing) impl Index for Bitv { #[inline] @@ -176,6 +178,21 @@ impl Index for Bitv { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +// FIXME(Gankro): NopeNopeNopeNopeNope (wait for IndexGet to be a thing) +impl Index for Bitv { + type Output = bool; + + #[inline] + fn index(&self, i: &uint) -> &bool { + if self.get(*i).expect("index out of bounds") { + &TRUE + } else { + &FALSE + } + } +} + /// Computes how many blocks are needed to store that many bits fn blocks_for_bits(bits: uint) -> uint { // If we want 17 bits, dividing by 32 will produce 0. So we add 1 to make sure we diff --git a/src/libcollections/btree/map.rs b/src/libcollections/btree/map.rs index 13178893723..e86e9326665 100644 --- a/src/libcollections/btree/map.rs +++ b/src/libcollections/btree/map.rs @@ -898,6 +898,8 @@ impl Show for BTreeMap { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl Index for BTreeMap where Q: BorrowFrom + Ord @@ -907,6 +909,20 @@ impl Index for BTreeMap } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl Index for BTreeMap + where Q: BorrowFrom + Ord +{ + type Output = V; + + fn index(&self, key: &Q) -> &V { + self.get(key).expect("no entry found for key") + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl IndexMut for BTreeMap where Q: BorrowFrom + Ord @@ -916,6 +932,18 @@ impl IndexMut for BTreeMap } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl IndexMut for BTreeMap + where Q: BorrowFrom + Ord +{ + type Output = V; + + fn index_mut(&mut self, key: &Q) -> &mut V { + self.get_mut(key).expect("no entry found for key") + } +} + /// Genericises over how to get the correct type of iterator from the correct type /// of Node ownership. trait Traverse { diff --git a/src/libcollections/ring_buf.rs b/src/libcollections/ring_buf.rs index eb58edbe453..dd78ae03c5a 100644 --- a/src/libcollections/ring_buf.rs +++ b/src/libcollections/ring_buf.rs @@ -1372,6 +1372,8 @@ impl> Hash for RingBuf { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl Index for RingBuf { #[inline] @@ -1380,6 +1382,19 @@ impl Index for RingBuf { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl Index for RingBuf { + type Output = A; + + #[inline] + fn index<'a>(&'a self, i: &uint) -> &'a A { + self.get(*i).expect("Out of bounds access") + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl IndexMut for RingBuf { #[inline] @@ -1388,6 +1403,17 @@ impl IndexMut for RingBuf { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl IndexMut for RingBuf { + type Output = A; + + #[inline] + fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut A { + self.get_mut(*i).expect("Out of bounds access") + } +} + #[stable] impl FromIterator for RingBuf { fn from_iter>(iterator: T) -> RingBuf { diff --git a/src/libcollections/vec.rs b/src/libcollections/vec.rs index 39eb37e3dd9..07338801872 100644 --- a/src/libcollections/vec.rs +++ b/src/libcollections/vec.rs @@ -1245,6 +1245,8 @@ impl> Hash for Vec { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[experimental = "waiting on Index stability"] impl Index for Vec { #[inline] @@ -1253,6 +1255,19 @@ impl Index for Vec { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[experimental = "waiting on Index stability"] +impl Index for Vec { + type Output = T; + + #[inline] + fn index<'a>(&'a self, index: &uint) -> &'a T { + &self.as_slice()[*index] + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] impl IndexMut for Vec { #[inline] fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T { @@ -1260,6 +1275,16 @@ impl IndexMut for Vec { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl IndexMut for Vec { + type Output = T; + + #[inline] + fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T { + &mut self.as_mut_slice()[*index] + } +} + impl ops::Slice for Vec { #[inline] fn as_slice_<'a>(&'a self) -> &'a [T] { diff --git a/src/libcollections/vec_map.rs b/src/libcollections/vec_map.rs index bf0c8f10e5f..91edbc7b54e 100644 --- a/src/libcollections/vec_map.rs +++ b/src/libcollections/vec_map.rs @@ -562,6 +562,8 @@ impl Extend<(uint, V)> for VecMap { } } +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl Index for VecMap { #[inline] @@ -570,6 +572,18 @@ impl Index for VecMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +impl Index for VecMap { + type Output = V; + + #[inline] + fn index<'a>(&'a self, i: &uint) -> &'a V { + self.get(i).expect("key not present") + } +} + +// NOTE(stage0): remove impl after a snapshot +#[cfg(stage0)] #[stable] impl IndexMut for VecMap { #[inline] @@ -578,6 +592,17 @@ impl IndexMut for VecMap { } } +#[cfg(not(stage0))] // NOTE(stage0): remove cfg after a snapshot +#[stable] +impl IndexMut for VecMap { + type Output = V; + + #[inline] + fn index_mut<'a>(&'a mut self, i: &uint) -> &'a mut V { + self.get_mut(i).expect("key not present") + } +} + macro_rules! iterator { (impl $name:ident -> $elem:ty, $($getter:ident),+) => { #[stable]