|
| 1 | +#[cfg(test)] |
| 2 | +mod tests; |
| 3 | + |
1 | 4 | use core::borrow::Borrow;
|
2 | 5 | use core::cmp::Ordering;
|
3 | 6 | use core::fmt::{self, Debug};
|
@@ -2220,5 +2223,52 @@ impl<K, V> BTreeMap<K, V> {
|
2220 | 2223 | }
|
2221 | 2224 | }
|
2222 | 2225 |
|
2223 |
| -#[cfg(test)] |
2224 |
| -mod tests; |
| 2226 | +#[allow(dead_code)] |
| 2227 | +fn assert_covariance() { |
| 2228 | + // Lifetime and both type parameters should be covariant for these types. |
| 2229 | + fn map<'new>(v: BTreeMap<&'static str, &'static str>) -> BTreeMap<&'new str, &'new str> { |
| 2230 | + v |
| 2231 | + } |
| 2232 | + fn iter<'new>( |
| 2233 | + v: Iter<'static, &'static str, &'static str>, |
| 2234 | + ) -> Iter<'new, &'new str, &'new str> { |
| 2235 | + v |
| 2236 | + } |
| 2237 | + fn into_iter<'new>(v: IntoIter<&'static str, &'static str>) -> IntoIter<&'new str, &'new str> { |
| 2238 | + v |
| 2239 | + } |
| 2240 | + fn keys<'new>( |
| 2241 | + v: Keys<'static, &'static str, &'static str>, |
| 2242 | + ) -> Keys<'new, &'new str, &'new str> { |
| 2243 | + v |
| 2244 | + } |
| 2245 | + fn values<'new>( |
| 2246 | + v: Values<'static, &'static str, &'static str>, |
| 2247 | + ) -> Values<'new, &'new str, &'new str> { |
| 2248 | + v |
| 2249 | + } |
| 2250 | + fn into_keys<'new>(v: IntoKeys<&'static str, &'static str>) -> IntoKeys<&'new str, &'new str> { |
| 2251 | + v |
| 2252 | + } |
| 2253 | + fn into_values<'new>( |
| 2254 | + v: IntoValues<&'static str, &'static str>, |
| 2255 | + ) -> IntoValues<&'new str, &'new str> { |
| 2256 | + v |
| 2257 | + } |
| 2258 | + fn range<'new>( |
| 2259 | + v: Range<'static, &'static str, &'static str>, |
| 2260 | + ) -> Range<'new, &'new str, &'new str> { |
| 2261 | + v |
| 2262 | + } |
| 2263 | + |
| 2264 | + // Lifetime should be covariant for these types. |
| 2265 | + fn iter_mut<'new>(v: IterMut<'static, u8, u8>) -> IterMut<'new, u8, u8> { |
| 2266 | + v |
| 2267 | + } |
| 2268 | + fn values_mut<'new>(v: ValuesMut<'static, u8, u8>) -> ValuesMut<'new, u8, u8> { |
| 2269 | + v |
| 2270 | + } |
| 2271 | + fn range_mut<'new>(v: RangeMut<'static, u8, u8>) -> RangeMut<'new, u8, u8> { |
| 2272 | + v |
| 2273 | + } |
| 2274 | +} |
0 commit comments