Skip to content

Commit 0031429

Browse files
committed
feat: use maro_metavar_expr to count macro repetitions and be able to use with_capacity in HashMap
1 parent d1dcdba commit 0031429

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

library/std/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@
303303
#![feature(link_cfg)]
304304
#![feature(linkage)]
305305
#![feature(macro_metavar_expr_concat)]
306+
#![feature(macro_metavar_expr)]
306307
#![feature(maybe_uninit_fill)]
307308
#![feature(min_specialization)]
308309
#![feature(must_not_suspend)]

library/std/src/macros.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,14 +414,15 @@ macro_rules! dbg {
414414
/// [`HashMap::new`]: crate::collections::HashMap::new
415415
/// [`HashMap::insert`]: crate::collections::HashMap::insert
416416
#[macro_export]
417+
#[allow_internal_unstable(macro_metavar_expr)]
417418
#[unstable(feature = "hash_map_macro", issue = "144032")]
418419
macro_rules! hash_map {
419420
() => {{
420421
::std::collections::HashMap::new()
421422
}};
422423

423424
( $( $key:expr => $value:expr ),* $(,)? ) => {{
424-
let mut map = ::std::collections::HashMap::new();
425+
let mut map = ::std::collections::HashMap::with_capacity( ${count($expr)} );
425426
$( map.insert($key, $value); )*
426427
map
427428
}}

0 commit comments

Comments
 (0)