1
Fork 0

Fix VecMap::iter_mut

It used to allow you to mutate the key, even though that can invalidate the map by creating duplicate keys.
This commit is contained in:
Oli Scherer 2021-07-19 16:38:14 +00:00
parent 7c89e389d0
commit d693a98f4e
2 changed files with 6 additions and 5 deletions

View file

@ -24,6 +24,7 @@
#![feature(new_uninit)] #![feature(new_uninit)]
#![feature(once_cell)] #![feature(once_cell)]
#![feature(maybe_uninit_uninit_array)] #![feature(maybe_uninit_uninit_array)]
#![feature(min_type_alias_impl_trait)]
#![allow(rustc::default_hash_types)] #![allow(rustc::default_hash_types)]
#![deny(unaligned_references)] #![deny(unaligned_references)]

View file

@ -1,6 +1,6 @@
use std::borrow::Borrow; use std::borrow::Borrow;
use std::iter::FromIterator; use std::iter::FromIterator;
use std::slice::{Iter, IterMut}; use std::slice::Iter;
use std::vec::IntoIter; use std::vec::IntoIter;
use crate::stable_hasher::{HashStable, StableHasher}; use crate::stable_hasher::{HashStable, StableHasher};
@ -67,7 +67,7 @@ where
self.into_iter() self.into_iter()
} }
pub fn iter_mut(&mut self) -> IterMut<'_, (K, V)> { pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut V)> {
self.into_iter() self.into_iter()
} }
} }
@ -108,12 +108,12 @@ impl<'a, K, V> IntoIterator for &'a VecMap<K, V> {
} }
impl<'a, K, V> IntoIterator for &'a mut VecMap<K, V> { impl<'a, K, V> IntoIterator for &'a mut VecMap<K, V> {
type Item = &'a mut (K, V); type Item = (&'a K, &'a mut V);
type IntoIter = IterMut<'a, (K, V)>; type IntoIter = impl Iterator<Item = Self::Item>;
#[inline] #[inline]
fn into_iter(self) -> Self::IntoIter { fn into_iter(self) -> Self::IntoIter {
self.0.iter_mut() self.0.iter_mut().map(|(k, v)| (&*k, v))
} }
} }