perf(str): static_ident! and static_str! macros guarantee const evaluation (#28340)

`static_ident!` and `static_str!` macros are intended to evaluate at compile time. This is especially valuable for `static_ident!` as we want the hash to be calculated at compile time.

Wrap both in a `const { ... }` block to ensure they are const-evaluated.
This commit is contained in:
overlookmotel committed 2026-10-29 01:08:46 +00:00
1 parent df908363ec
commit 2683225190
2 files changed
+4 -2

No files matched your search

+2 -1
View File
@@ -581,7 +581,8 @@ pub type ArenaIdentHashSet<'alloc> =
#[macro_export]
macro_rules! static_ident {
($s:literal) => {
$crate::__internal::new_const_ident($s)
// `const { ... }` block guarantees evaluation at compile time
const { $crate::__internal::new_const_ident($s) }
};
}
+2 -1
View File
@@ -341,7 +341,8 @@ impl ESTree for Str<'_> {
#[macro_export]
macro_rules! static_str {
($s:literal) => {
$crate::Str::new_const($s)
// `const { ... }` block guarantees evaluation at compile time
const { $crate::Str::new_const($s) }
};
}