fix(str): fix hygiene of format_ident! and format_str! macros (#24886)

Avoid `use` statements in these macros, to avoid naming clashes with the user-provided input.
This commit is contained in:
overlookmotel committed 2026-07-24 10:04:52 +00:00
1 parent 4d6f623cda
commit e7d5c7801d
2 files changed
+6 -12

No files matched your search

+3 -6
View File
@@ -603,12 +603,9 @@ macro_rules! static_ident {
#[macro_export]
macro_rules! format_ident {
($alloc:expr, $($arg:tt)*) => {{
use ::std::{write, fmt::Write};
use $crate::{Ident, __internal::ArenaStringBuilder};
let mut s = ArenaStringBuilder::new_in($alloc);
write!(s, $($arg)*).unwrap();
Ident::from(s)
let mut s = $crate::__internal::ArenaStringBuilder::new_in($alloc);
::std::fmt::Write::write_fmt(&mut s, ::std::format_args!($($arg)*)).unwrap();
$crate::Ident::from(s)
}}
}
+3 -6
View File
@@ -334,12 +334,9 @@ impl ESTree for Str<'_> {
#[macro_export]
macro_rules! format_str {
($alloc:expr, $($arg:tt)*) => {{
use ::std::{write, fmt::Write};
use $crate::{Str, __internal::ArenaStringBuilder};
let mut s = ArenaStringBuilder::new_in($alloc);
write!(s, $($arg)*).unwrap();
Str::from(s)
let mut s = $crate::__internal::ArenaStringBuilder::new_in($alloc);
::std::fmt::Write::write_fmt(&mut s, ::std::format_args!($($arg)*)).unwrap();
$crate::Str::from(s)
}}
}