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?
This commit is contained in:
commit
25c8e9ac17
@ -1294,7 +1294,7 @@ impl<K: Ord, V> BTreeMap<K, V> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, K: 'a, V: 'a> IntoIterator for &'a BTreeMap<K, V> {
|
||||
impl<'a, K, V> IntoIterator for &'a BTreeMap<K, V> {
|
||||
type Item = (&'a K, &'a V);
|
||||
type IntoIter = Iter<'a, K, V>;
|
||||
|
||||
@ -1363,7 +1363,7 @@ impl<K, V> Clone for Iter<'_, K, V> {
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
impl<'a, K: 'a, V: 'a> IntoIterator for &'a mut BTreeMap<K, V> {
|
||||
impl<'a, K, V> IntoIterator for &'a mut BTreeMap<K, V> {
|
||||
type Item = (&'a K, &'a mut V);
|
||||
type IntoIter = IterMut<'a, K, V>;
|
||||
|
||||
|
23
src/test/ui/btreemap/btreemap_into_iterator_lifetime.rs
Normal file
23
src/test/ui/btreemap/btreemap_into_iterator_lifetime.rs
Normal file
@ -0,0 +1,23 @@
|
||||
// check-pass
|
||||
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
|
||||
trait Map
|
||||
where
|
||||
for<'a> &'a Self: IntoIterator<Item = (&'a Self::Key, &'a Self::Value)>,
|
||||
{
|
||||
type Key;
|
||||
type Value;
|
||||
}
|
||||
|
||||
impl<K, V> Map for HashMap<K, V> {
|
||||
type Key = K;
|
||||
type Value = V;
|
||||
}
|
||||
|
||||
impl<K, V> Map for BTreeMap<K, V> {
|
||||
type Key = K;
|
||||
type Value = V;
|
||||
}
|
||||
|
||||
fn main() {}
|
Loading…
x
Reference in New Issue
Block a user