Skip to content

Commit 25c8e9a

Browse files
authored
Rollup merge of #75203 - canova:btreemap-into-iter, r=dtolnay
Make `IntoIterator` lifetime bounds of `&BTreeMap` match with `&HashMap` This is a pretty small change on the lifetime bounds of `IntoIterator` implementations of both `&BTreeMap` and `&mut BTreeMap`. This is loosening the lifetime bounds, so more code should be accepted with this PR. This is lifetime bounds will still be implicit since we have `type Item = (&'a K, &'a V);` in the implementation. This change will make the HashMap and BTreeMap share the same signature, so we can share the same function/trait with both HashMap and BTreeMap in the code. Fixes #74034. r? @dtolnay hey, I was touching this file on my previous PR and wanted to fix this on the way. Would you mind taking a look at this, or redirecting it if you are busy?
2 parents 5b1ed09 + cedf96c commit 25c8e9a

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

library/alloc/src/collections/btree/map.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1294,7 +1294,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
12941294
}
12951295

12961296
#[stable(feature = "rust1", since = "1.0.0")]
1297-
impl<'a, K: 'a, V: 'a> IntoIterator for &'a BTreeMap<K, V> {
1297+
impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
12981298
type Item = (&'a K, &'a V);
12991299
type IntoIter = Iter<'a, K, V>;
13001300

@@ -1363,7 +1363,7 @@ impl<K, V> Clone for Iter<'_, K, V> {
13631363
}
13641364

13651365
#[stable(feature = "rust1", since = "1.0.0")]
1366-
impl<'a, K: 'a, V: 'a> IntoIterator for &'a mut BTreeMap<K, V> {
1366+
impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> {
13671367
type Item = (&'a K, &'a mut V);
13681368
type IntoIter = IterMut<'a, K, V>;
13691369

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// check-pass
2+
3+
use std::collections::{BTreeMap, HashMap};
4+
5+
trait Map
6+
where
7+
for<'a> &'a Self: IntoIterator<Item = (&'a Self::Key, &'a Self::Value)>,
8+
{
9+
type Key;
10+
type Value;
11+
}
12+
13+
impl<K, V> Map for HashMap<K, V> {
14+
type Key = K;
15+
type Value = V;
16+
}
17+
18+
impl<K, V> Map for BTreeMap<K, V> {
19+
type Key = K;
20+
type Value = V;
21+
}
22+
23+
fn main() {}

0 commit comments

Comments
 (0)