From a81ed52f5830b6a305ad8e8547196744d460afa0 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 23 Oct 2025 12:23:30 -0700 Subject: [PATCH 1/2] Add a regression test for rust-lang/rust#147971 --- library/std/tests/ambiguous-hash_map.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 library/std/tests/ambiguous-hash_map.rs diff --git a/library/std/tests/ambiguous-hash_map.rs b/library/std/tests/ambiguous-hash_map.rs new file mode 100644 index 0000000000000..bd5ae5a8957b5 --- /dev/null +++ b/library/std/tests/ambiguous-hash_map.rs @@ -0,0 +1,17 @@ +//! Make sure that a `std` macro `hash_map!` does not cause ambiguity +//! with a local glob import with the same name. +//! +//! See regression https://github.com/rust-lang/rust/issues/147971 + +mod module { + macro_rules! hash_map { + () => {}; + } + pub(crate) use hash_map; +} + +use module::*; + +fn main() { + hash_map! {} +} From c01682ebf603355795e870afdc28bd0c3bfe2ef5 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Thu, 23 Oct 2025 12:23:59 -0700 Subject: [PATCH 2/2] Revert "feat: implement `hash_map!` macro" This reverts commit 066023e47c0c92e7edefd60831ce7d6f15f23750. --- library/std/src/lib.rs | 2 -- library/std/src/macros.rs | 74 --------------------------------------- 2 files changed, 76 deletions(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 60c8f53a0cc40..a8c50cec01e0b 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -290,8 +290,6 @@ #![feature(ffi_const)] #![feature(formatting_options)] #![feature(funnel_shifts)] -#![feature(hash_map_internals)] -#![feature(hash_map_macro)] #![feature(if_let_guard)] #![feature(intra_doc_pointers)] #![feature(iter_advance_by)] diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index 254570ae9c836..25e2b7ea13703 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -379,77 +379,3 @@ macro_rules! dbg { ($($crate::dbg!($val)),+,) }; } - -#[doc(hidden)] -#[macro_export] -#[allow_internal_unstable(hash_map_internals)] -#[unstable(feature = "hash_map_internals", issue = "none")] -macro_rules! repetition_utils { - (@count $($tokens:tt),*) => {{ - [$($crate::repetition_utils!(@replace $tokens => ())),*].len() - }}; - - (@replace $x:tt => $y:tt) => { $y } -} - -/// Creates a [`HashMap`] containing the arguments. -/// -/// `hash_map!` allows specifying the entries that make -/// up the [`HashMap`] where the key and value are separated by a `=>`. -/// -/// The entries are separated by commas with a trailing comma being allowed. -/// -/// It is semantically equivalent to using repeated [`HashMap::insert`] -/// on a newly created hashmap. -/// -/// `hash_map!` will attempt to avoid repeated reallocations by -/// using [`HashMap::with_capacity`]. -/// -/// # Examples -/// -/// ```rust -/// #![feature(hash_map_macro)] -/// -/// let map = hash_map! { -/// "key" => "value", -/// "key1" => "value1" -/// }; -/// -/// assert_eq!(map.get("key"), Some(&"value")); -/// assert_eq!(map.get("key1"), Some(&"value1")); -/// assert!(map.get("brrrrrrooooommm").is_none()); -/// ``` -/// -/// And with a trailing comma -/// -///```rust -/// #![feature(hash_map_macro)] -/// -/// let map = hash_map! { -/// "key" => "value", // notice the , -/// }; -/// -/// assert_eq!(map.get("key"), Some(&"value")); -/// ``` -/// -/// The key and value are moved into the HashMap. -/// -/// [`HashMap`]: crate::collections::HashMap -/// [`HashMap::insert`]: crate::collections::HashMap::insert -/// [`HashMap::with_capacity`]: crate::collections::HashMap::with_capacity -#[macro_export] -#[allow_internal_unstable(hash_map_internals)] -#[unstable(feature = "hash_map_macro", issue = "144032")] -macro_rules! hash_map { - () => {{ - $crate::collections::HashMap::new() - }}; - - ( $( $key:expr => $value:expr ),* $(,)? ) => {{ - let mut map = $crate::collections::HashMap::with_capacity( - const { $crate::repetition_utils!(@count $($key),*) } - ); - $( map.insert($key, $value); )* - map - }} -}