Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize map_many_mut feature #136152

Merged
merged 2 commits into from
Feb 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_session/src/config/cfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ impl CheckCfg {
Some(values_target_os),
Some(values_target_pointer_width),
Some(values_target_vendor),
] = self.expecteds.get_many_mut(VALUES)
] = self.expecteds.get_disjoint_mut(VALUES)
else {
panic!("unable to get all the check-cfg values buckets");
};
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_session/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
#![allow(internal_features)]
#![feature(iter_intersperse)]
#![feature(let_chains)]
#![feature(map_many_mut)]
#![feature(rustc_attrs)]
#![warn(unreachable_pub)]
// tidy-alphabetical-end
Expand Down
32 changes: 17 additions & 15 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -969,7 +969,6 @@ where
/// # Examples
///
/// ```
/// #![feature(map_many_mut)]
/// use std::collections::HashMap;
///
/// let mut libraries = HashMap::new();
Expand All @@ -979,13 +978,13 @@ where
/// libraries.insert("Library of Congress".to_string(), 1800);
///
/// // Get Athenæum and Bodleian Library
/// let [Some(a), Some(b)] = libraries.get_many_mut([
/// let [Some(a), Some(b)] = libraries.get_disjoint_mut([
/// "Athenæum",
/// "Bodleian Library",
/// ]) else { panic!() };
///
/// // Assert values of Athenæum and Library of Congress
/// let got = libraries.get_many_mut([
/// let got = libraries.get_disjoint_mut([
/// "Athenæum",
/// "Library of Congress",
/// ]);
Expand All @@ -998,7 +997,7 @@ where
/// );
///
/// // Missing keys result in None
/// let got = libraries.get_many_mut([
/// let got = libraries.get_disjoint_mut([
/// "Athenæum",
/// "New York Public Library",
/// ]);
Expand All @@ -1012,21 +1011,24 @@ where
/// ```
///
/// ```should_panic
/// #![feature(map_many_mut)]
/// use std::collections::HashMap;
///
/// let mut libraries = HashMap::new();
/// libraries.insert("Athenæum".to_string(), 1807);
///
/// // Duplicate keys panic!
/// let got = libraries.get_many_mut([
/// let got = libraries.get_disjoint_mut([
/// "Athenæum",
/// "Athenæum",
/// ]);
/// ```
#[inline]
#[unstable(feature = "map_many_mut", issue = "97601")]
pub fn get_many_mut<Q: ?Sized, const N: usize>(&mut self, ks: [&Q; N]) -> [Option<&'_ mut V>; N]
#[doc(alias = "get_many_mut")]
#[stable(feature = "map_many_mut", since = "CURRENT_RUSTC_VERSION")]
pub fn get_disjoint_mut<Q: ?Sized, const N: usize>(
&mut self,
ks: [&Q; N],
) -> [Option<&'_ mut V>; N]
where
K: Borrow<Q>,
Q: Hash + Eq,
Expand All @@ -1040,7 +1042,7 @@ where
/// Returns an array of length `N` with the results of each query. `None` will be used if
/// the key is missing.
///
/// For a safe alternative see [`get_many_mut`](`HashMap::get_many_mut`).
/// For a safe alternative see [`get_disjoint_mut`](`HashMap::get_disjoint_mut`).
///
/// # Safety
///
Expand All @@ -1052,7 +1054,6 @@ where
/// # Examples
///
/// ```
/// #![feature(map_many_mut)]
/// use std::collections::HashMap;
///
/// let mut libraries = HashMap::new();
Expand All @@ -1062,13 +1063,13 @@ where
/// libraries.insert("Library of Congress".to_string(), 1800);
///
/// // SAFETY: The keys do not overlap.
/// let [Some(a), Some(b)] = (unsafe { libraries.get_many_unchecked_mut([
/// let [Some(a), Some(b)] = (unsafe { libraries.get_disjoint_unchecked_mut([
/// "Athenæum",
/// "Bodleian Library",
/// ]) }) else { panic!() };
///
/// // SAFETY: The keys do not overlap.
/// let got = unsafe { libraries.get_many_unchecked_mut([
/// let got = unsafe { libraries.get_disjoint_unchecked_mut([
/// "Athenæum",
/// "Library of Congress",
/// ]) };
Expand All @@ -1081,16 +1082,17 @@ where
/// );
///
/// // SAFETY: The keys do not overlap.
/// let got = unsafe { libraries.get_many_unchecked_mut([
/// let got = unsafe { libraries.get_disjoint_unchecked_mut([
/// "Athenæum",
/// "New York Public Library",
/// ]) };
/// // Missing keys result in None
/// assert_eq!(got, [Some(&mut 1807), None]);
/// ```
#[inline]
#[unstable(feature = "map_many_mut", issue = "97601")]
pub unsafe fn get_many_unchecked_mut<Q: ?Sized, const N: usize>(
#[doc(alias = "get_many_unchecked_mut")]
#[stable(feature = "map_many_mut", since = "CURRENT_RUSTC_VERSION")]
pub unsafe fn get_disjoint_unchecked_mut<Q: ?Sized, const N: usize>(
&mut self,
ks: [&Q; N],
) -> [Option<&'_ mut V>; N]
Expand Down
Loading