diff options
| author | Jonathan S <gereeter+code@gmail.com> | 2016-03-30 21:57:31 -0500 |
|---|---|---|
| committer | Jonathan S <gereeter+code@gmail.com> | 2016-03-30 22:02:36 -0500 |
| commit | 589108baf644ea44a10a7258d67da254e1e09fae (patch) | |
| tree | 3eadc85319441c15cd0e979e4fc418e4bd2081cb /src/libstd/collections | |
| parent | 1639f2d2899310038635be2c307b60adf2bde125 (diff) | |
| download | rust-589108baf644ea44a10a7258d67da254e1e09fae.tar.gz rust-589108baf644ea44a10a7258d67da254e1e09fae.zip | |
Test that HashMap, HashSet, and their iterators are properly covariant
Diffstat (limited to 'src/libstd/collections')
| -rw-r--r-- | src/libstd/collections/hash/map.rs | 14 | ||||
| -rw-r--r-- | src/libstd/collections/hash/set.rs | 15 |
2 files changed, 29 insertions, 0 deletions
diff --git a/src/libstd/collections/hash/map.rs b/src/libstd/collections/hash/map.rs index 77ce27476fd..80b5448800e 100644 --- a/src/libstd/collections/hash/map.rs +++ b/src/libstd/collections/hash/map.rs @@ -1670,6 +1670,20 @@ impl<K, S, Q: ?Sized> super::Recover<Q> for HashMap<K, (), S> } } +#[allow(dead_code)] +fn assert_covariance() { + fn map_key<'new>(v: HashMap<&'static str, u8>) -> HashMap<&'new str, u8> { v } + fn map_val<'new>(v: HashMap<u8, &'static str>) -> HashMap<u8, &'new str> { v } + fn iter_key<'a, 'new>(v: Iter<'a, &'static str, u8>) -> Iter<'a, &'new str, u8> { v } + fn iter_val<'a, 'new>(v: Iter<'a, u8, &'static str>) -> Iter<'a, u8, &'new str> { v } + fn into_iter_key<'new>(v: IntoIter<&'static str, u8>) -> IntoIter<&'new str, u8> { v } + fn into_iter_val<'new>(v: IntoIter<u8, &'static str>) -> IntoIter<u8, &'new str> { v } + fn keys_key<'a, 'new>(v: Keys<'a, &'static str, u8>) -> Keys<'a, &'new str, u8> { v } + fn keys_val<'a, 'new>(v: Keys<'a, u8, &'static str>) -> Keys<'a, u8, &'new str> { v } + fn values_key<'a, 'new>(v: Values<'a, &'static str, u8>) -> Values<'a, &'new str, u8> { v } + fn values_val<'a, 'new>(v: Values<'a, u8, &'static str>) -> Values<'a, u8, &'new str> { v } +} + #[cfg(test)] mod test_map { use prelude::v1::*; diff --git a/src/libstd/collections/hash/set.rs b/src/libstd/collections/hash/set.rs index 7e79aef300b..954adf313be 100644 --- a/src/libstd/collections/hash/set.rs +++ b/src/libstd/collections/hash/set.rs @@ -1024,6 +1024,21 @@ impl<'a, T, S> Iterator for Union<'a, T, S> fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() } } +#[allow(dead_code)] +fn assert_covariance() { + fn set<'new>(v: HashSet<&'static str>) -> HashSet<&'new str> { v } + fn iter<'a, 'new>(v: Iter<'a, &'static str>) -> Iter<'a, &'new str> { v } + fn into_iter<'new>(v: IntoIter<&'static str>) -> IntoIter<&'new str> { v } + fn difference<'a, 'new>(v: Difference<'a, &'static str, RandomState>) + -> Difference<'a, &'new str, RandomState> { v } + fn symmetric_difference<'a, 'new>(v: SymmetricDifference<'a, &'static str, RandomState>) + -> SymmetricDifference<'a, &'new str, RandomState> { v } + fn intersection<'a, 'new>(v: Intersection<'a, &'static str, RandomState>) + -> Intersection<'a, &'new str, RandomState> { v } + fn union<'a, 'new>(v: Union<'a, &'static str, RandomState>) + -> Union<'a, &'new str, RandomState> { v } +} + #[cfg(test)] mod test_set { use prelude::v1::*; |
