Skip to content

Commit 7bc39e0

Browse files
committed
Auto merge of rust-lang#131148 - Urgau:hashbrown-0.15, r=<try>
Update hashbrown to 0.15 and adjust some methods This PR updates `hashbrown` to 0.15 in the standard library and adjust some methods as well as removing some as they no longer exists in Hashbrown it-self. - `HashMap::get_many_mut` change API to return array-of-Option - `HashMap::{replace_entry, replace_key}` are removed, FCP close [already finished](rust-lang#44286 (comment)) - `HashSet::get_or_insert_owned` is removed as it no longer exists in hashbrown Closes rust-lang#44286 r? `@Amanieu`
2 parents 9e3e517 + 37e1c95 commit 7bc39e0

File tree

5 files changed

+70
-129
lines changed

5 files changed

+70
-129
lines changed

compiler/rustc_session/src/config/cfg.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -402,18 +402,18 @@ impl CheckCfg {
402402
// Get all values map at once otherwise it would be costly.
403403
// (8 values * 220 targets ~= 1760 times, at the time of writing this comment).
404404
let [
405-
values_target_abi,
406-
values_target_arch,
407-
values_target_endian,
408-
values_target_env,
409-
values_target_family,
410-
values_target_os,
411-
values_target_pointer_width,
412-
values_target_vendor,
413-
] = self
414-
.expecteds
415-
.get_many_mut(VALUES)
416-
.expect("unable to get all the check-cfg values buckets");
405+
Some(values_target_abi),
406+
Some(values_target_arch),
407+
Some(values_target_endian),
408+
Some(values_target_env),
409+
Some(values_target_family),
410+
Some(values_target_os),
411+
Some(values_target_pointer_width),
412+
Some(values_target_vendor),
413+
] = self.expecteds.get_many_mut(VALUES)
414+
else {
415+
panic!("unable to get all the check-cfg values buckets");
416+
};
417417

418418
for target in TARGETS
419419
.iter()

library/Cargo.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ dependencies = [
135135

136136
[[package]]
137137
name = "hashbrown"
138-
version = "0.14.5"
138+
version = "0.15.0"
139139
source = "registry+https://github.com/rust-lang/crates.io-index"
140-
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
140+
checksum = "1e087f84d4f86bf4b218b927129862374b72199ae7d8657835f1e89000eea4fb"
141141
dependencies = [
142142
"allocator-api2",
143143
"compiler_builtins",

library/std/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ core = { path = "../core", public = true }
2020
compiler_builtins = { version = "0.1.130" }
2121
profiler_builtins = { path = "../profiler_builtins", optional = true }
2222
unwind = { path = "../unwind" }
23-
hashbrown = { version = "0.14", default-features = false, features = [
23+
hashbrown = { version = "0.15", default-features = false, features = [
2424
'rustc-dep-of-std',
2525
] }
2626
# FIXME(#127890): `object` depends on `memchr`, but `memchr` > v2.5 causes

library/std/src/collections/hash/map.rs

+55-82
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,11 @@ where
909909
/// Attempts to get mutable references to `N` values in the map at once.
910910
///
911911
/// Returns an array of length `N` with the results of each query. For soundness, at most one
912-
/// mutable reference will be returned to any value. `None` will be returned if any of the
913-
/// keys are duplicates or missing.
912+
/// mutable reference will be returned to any value. `None` will be used if the key is missing.
913+
///
914+
/// # Panics
915+
///
916+
/// Panics if any keys are overlapping.
914917
///
915918
/// # Examples
916919
///
@@ -924,35 +927,55 @@ where
924927
/// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
925928
/// libraries.insert("Library of Congress".to_string(), 1800);
926929
///
930+
/// // Get Athenæum and Bodleian Library
931+
/// let [Some(a), Some(b)] = libraries.get_many_mut([
932+
/// "Athenæum",
933+
/// "Bodleian Library",
934+
/// ]) else { panic!() };
935+
///
936+
/// // Assert values of Athenæum and Library of Congress
927937
/// let got = libraries.get_many_mut([
928938
/// "Athenæum",
929939
/// "Library of Congress",
930940
/// ]);
931941
/// assert_eq!(
932942
/// got,
933-
/// Some([
934-
/// &mut 1807,
935-
/// &mut 1800,
936-
/// ]),
943+
/// [
944+
/// Some(&mut 1807),
945+
/// Some(&mut 1800),
946+
/// ],
937947
/// );
938948
///
939949
/// // Missing keys result in None
940950
/// let got = libraries.get_many_mut([
941951
/// "Athenæum",
942952
/// "New York Public Library",
943953
/// ]);
944-
/// assert_eq!(got, None);
954+
/// assert_eq!(
955+
/// got,
956+
/// [
957+
/// Some(&mut 1807),
958+
/// None
959+
/// ]
960+
/// );
961+
/// ```
962+
///
963+
/// ```should_panic
964+
/// #![feature(map_many_mut)]
965+
/// use std::collections::HashMap;
945966
///
946-
/// // Duplicate keys result in None
967+
/// let mut libraries = HashMap::new();
968+
/// libraries.insert("Athenæum".to_string(), 1807);
969+
///
970+
/// // Duplicate keys panic!
947971
/// let got = libraries.get_many_mut([
948972
/// "Athenæum",
949973
/// "Athenæum",
950974
/// ]);
951-
/// assert_eq!(got, None);
952975
/// ```
953976
#[inline]
954977
#[unstable(feature = "map_many_mut", issue = "97601")]
955-
pub fn get_many_mut<Q: ?Sized, const N: usize>(&mut self, ks: [&Q; N]) -> Option<[&'_ mut V; N]>
978+
pub fn get_many_mut<Q: ?Sized, const N: usize>(&mut self, ks: [&Q; N]) -> [Option<&'_ mut V>; N]
956979
where
957980
K: Borrow<Q>,
958981
Q: Hash + Eq,
@@ -963,10 +986,10 @@ where
963986
/// Attempts to get mutable references to `N` values in the map at once, without validating that
964987
/// the values are unique.
965988
///
966-
/// Returns an array of length `N` with the results of each query. `None` will be returned if
967-
/// any of the keys are missing.
989+
/// Returns an array of length `N` with the results of each query. `None` will be used if
990+
/// the key is missing.
968991
///
969-
/// For a safe alternative see [`get_many_mut`](Self::get_many_mut).
992+
/// For a safe alternative see [`get_many_mut`](`HashMap::get_many_mut`).
970993
///
971994
/// # Safety
972995
///
@@ -987,31 +1010,39 @@ where
9871010
/// libraries.insert("Herzogin-Anna-Amalia-Bibliothek".to_string(), 1691);
9881011
/// libraries.insert("Library of Congress".to_string(), 1800);
9891012
///
990-
/// let got = libraries.get_many_mut([
1013+
/// // SAFETY: The keys do not overlap.
1014+
/// let [Some(a), Some(b)] = (unsafe { libraries.get_many_unchecked_mut([
1015+
/// "Athenæum",
1016+
/// "Bodleian Library",
1017+
/// ]) }) else { panic!() };
1018+
///
1019+
/// // SAFETY: The keys do not overlap.
1020+
/// let got = unsafe { libraries.get_many_unchecked_mut([
9911021
/// "Athenæum",
9921022
/// "Library of Congress",
993-
/// ]);
1023+
/// ]) };
9941024
/// assert_eq!(
9951025
/// got,
996-
/// Some([
997-
/// &mut 1807,
998-
/// &mut 1800,
999-
/// ]),
1026+
/// [
1027+
/// Some(&mut 1807),
1028+
/// Some(&mut 1800),
1029+
/// ],
10001030
/// );
10011031
///
1002-
/// // Missing keys result in None
1003-
/// let got = libraries.get_many_mut([
1032+
/// // SAFETY: The keys do not overlap.
1033+
/// let got = unsafe { libraries.get_many_unchecked_mut([
10041034
/// "Athenæum",
10051035
/// "New York Public Library",
1006-
/// ]);
1007-
/// assert_eq!(got, None);
1036+
/// ]) };
1037+
/// // Missing keys result in None
1038+
/// assert_eq!(got, [Some(&mut 1807), None]);
10081039
/// ```
10091040
#[inline]
10101041
#[unstable(feature = "map_many_mut", issue = "97601")]
10111042
pub unsafe fn get_many_unchecked_mut<Q: ?Sized, const N: usize>(
10121043
&mut self,
10131044
ks: [&Q; N],
1014-
) -> Option<[&'_ mut V; N]>
1045+
) -> [Option<&'_ mut V>; N]
10151046
where
10161047
K: Borrow<Q>,
10171048
Q: Hash + Eq,
@@ -2978,64 +3009,6 @@ impl<'a, K, V> OccupiedEntry<'a, K, V> {
29783009
pub fn remove(self) -> V {
29793010
self.base.remove()
29803011
}
2981-
2982-
/// Replaces the entry, returning the old key and value. The new key in the hash map will be
2983-
/// the key used to create this entry.
2984-
///
2985-
/// # Examples
2986-
///
2987-
/// ```
2988-
/// #![feature(map_entry_replace)]
2989-
/// use std::collections::hash_map::{Entry, HashMap};
2990-
/// use std::rc::Rc;
2991-
///
2992-
/// let mut map: HashMap<Rc<String>, u32> = HashMap::new();
2993-
/// map.insert(Rc::new("Stringthing".to_string()), 15);
2994-
///
2995-
/// let my_key = Rc::new("Stringthing".to_string());
2996-
///
2997-
/// if let Entry::Occupied(entry) = map.entry(my_key) {
2998-
/// // Also replace the key with a handle to our other key.
2999-
/// let (old_key, old_value): (Rc<String>, u32) = entry.replace_entry(16);
3000-
/// }
3001-
///
3002-
/// ```
3003-
#[inline]
3004-
#[unstable(feature = "map_entry_replace", issue = "44286")]
3005-
pub fn replace_entry(self, value: V) -> (K, V) {
3006-
self.base.replace_entry(value)
3007-
}
3008-
3009-
/// Replaces the key in the hash map with the key used to create this entry.
3010-
///
3011-
/// # Examples
3012-
///
3013-
/// ```
3014-
/// #![feature(map_entry_replace)]
3015-
/// use std::collections::hash_map::{Entry, HashMap};
3016-
/// use std::rc::Rc;
3017-
///
3018-
/// let mut map: HashMap<Rc<String>, u32> = HashMap::new();
3019-
/// let known_strings: Vec<Rc<String>> = Vec::new();
3020-
///
3021-
/// // Initialise known strings, run program, etc.
3022-
///
3023-
/// reclaim_memory(&mut map, &known_strings);
3024-
///
3025-
/// fn reclaim_memory(map: &mut HashMap<Rc<String>, u32>, known_strings: &[Rc<String>] ) {
3026-
/// for s in known_strings {
3027-
/// if let Entry::Occupied(entry) = map.entry(Rc::clone(s)) {
3028-
/// // Replaces the entry's key with our version of it in `known_strings`.
3029-
/// entry.replace_key();
3030-
/// }
3031-
/// }
3032-
/// }
3033-
/// ```
3034-
#[inline]
3035-
#[unstable(feature = "map_entry_replace", issue = "44286")]
3036-
pub fn replace_key(self) -> K {
3037-
self.base.replace_key()
3038-
}
30393012
}
30403013

30413014
impl<'a, K: 'a, V: 'a> VacantEntry<'a, K, V> {

library/std/src/collections/hash/set.rs

-32
Original file line numberDiff line numberDiff line change
@@ -724,38 +724,6 @@ where
724724
self.base.get_or_insert(value)
725725
}
726726

727-
/// Inserts an owned copy of the given `value` into the set if it is not
728-
/// present, then returns a reference to the value in the set.
729-
///
730-
/// # Examples
731-
///
732-
/// ```
733-
/// #![feature(hash_set_entry)]
734-
///
735-
/// use std::collections::HashSet;
736-
///
737-
/// let mut set: HashSet<String> = ["cat", "dog", "horse"]
738-
/// .iter().map(|&pet| pet.to_owned()).collect();
739-
///
740-
/// assert_eq!(set.len(), 3);
741-
/// for &pet in &["cat", "dog", "fish"] {
742-
/// let value = set.get_or_insert_owned(pet);
743-
/// assert_eq!(value, pet);
744-
/// }
745-
/// assert_eq!(set.len(), 4); // a new "fish" was inserted
746-
/// ```
747-
#[inline]
748-
#[unstable(feature = "hash_set_entry", issue = "60896")]
749-
pub fn get_or_insert_owned<Q: ?Sized>(&mut self, value: &Q) -> &T
750-
where
751-
T: Borrow<Q>,
752-
Q: Hash + Eq + ToOwned<Owned = T>,
753-
{
754-
// Although the raw entry gives us `&mut T`, we only return `&T` to be consistent with
755-
// `get`. Key mutation is "raw" because you're not supposed to affect `Eq` or `Hash`.
756-
self.base.get_or_insert_owned(value)
757-
}
758-
759727
/// Inserts a value computed from `f` into the set if the given `value` is
760728
/// not present, then returns a reference to the value in the set.
761729
///

0 commit comments

Comments
 (0)