Skip to content

Commit 658e3d3

Browse files
committed
fix: revert from macro_metavar_expr usage to custom hash_map_internals macro for constant count in with_capacity invocation
1 parent 520e439 commit 658e3d3

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

library/std/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@
294294
#![feature(f128)]
295295
#![feature(ffi_const)]
296296
#![feature(formatting_options)]
297+
#![feature(hash_map_internals)]
297298
#![feature(hash_map_macro)]
298299
#![feature(if_let_guard)]
299300
#![feature(intra_doc_pointers)]
@@ -302,7 +303,6 @@
302303
#![feature(lang_items)]
303304
#![feature(link_cfg)]
304305
#![feature(linkage)]
305-
#![feature(macro_metavar_expr)]
306306
#![feature(macro_metavar_expr_concat)]
307307
#![feature(maybe_uninit_fill)]
308308
#![feature(min_specialization)]

library/std/src/macros.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,17 @@ macro_rules! dbg {
380380
};
381381
}
382382

383+
#[doc(hidden)]
384+
#[macro_export]
385+
#[unstable(feature = "hash_map_internals", issue = "none")]
386+
macro_rules! repetition_utils {
387+
(@count $($tokens:tt),*) => {{
388+
[$($crate::repetition_count!(@replace $tokens => ())),*].len()
389+
}};
390+
391+
(@replace $x:tt => $y:tt) => { $y }
392+
}
393+
383394
/// Creates a [`HashMap`] containing the arguments.
384395
///
385396
/// This macro creates or either an empty [`HashMap`] using
@@ -423,15 +434,17 @@ macro_rules! dbg {
423434
/// [`HashMap::new`]: crate::collections::HashMap::new
424435
/// [`HashMap::insert`]: crate::collections::HashMap::insert
425436
#[macro_export]
426-
#[allow_internal_unstable(macro_metavar_expr)]
437+
#[allow_internal_unstable(hash_map_internals)]
427438
#[unstable(feature = "hash_map_macro", issue = "144032")]
428439
macro_rules! hash_map {
429440
() => {{
430441
$crate::collections::HashMap::new()
431442
}};
432443

433444
( $( $key:expr => $value:expr ),* $(,)? ) => {{
434-
let mut map = $crate::collections::HashMap::with_capacity( ${count($key)} );
445+
let mut map = $crate::collections::HashMap::with_capacity(
446+
const { $crate::repetition_utils(@count $($key),*) }
447+
);
435448
$( map.insert($key, $value); )*
436449
map
437450
}}

0 commit comments

Comments
 (0)