diff --git a/compiler/ident/src/lib.rs b/compiler/ident/src/lib.rs index 6c4163e5d4..21e5a64063 100644 --- a/compiler/ident/src/lib.rs +++ b/compiler/ident/src/lib.rs @@ -5,6 +5,7 @@ use core::convert::From; use core::{fmt, mem, ptr, slice}; use std::alloc::{alloc, dealloc, Layout}; use std::os::raw::c_char; +use std::str::FromStr; /// A string which can store identifiers using the small string optimization. /// It relies on the invariant that it cannot store null characters to store @@ -102,13 +103,8 @@ impl IdentStr { unsafe { mem::transmute::<[u8; mem::size_of::()], Self>(bytes) } } - pub fn from_array_string( - array_string: arrayvec::ArrayString<{ Self::SMALL_STR_BYTES }>, - ) -> Self { - Self::small_str_from_bytes(array_string.as_bytes()) - } - - fn from_str(str: &str) -> Self { + #[allow(clippy::should_implement_trait)] + pub fn from_str(str: &str) -> Self { let slice = str.as_bytes(); let len = slice.len(); diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index c7938a629c..46b5f25be5 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -636,12 +636,15 @@ impl IdentIds { pub fn gen_unique(&mut self) -> IdentId { use std::fmt::Write; - let mut temp: arrayvec::ArrayString<15> = arrayvec::ArrayString::new(); - write!(temp, "{}", self.next_generated_name).unwrap(); - let ident = Ident(IdentStr::from_array_string(temp)); - + let index: u32 = self.next_generated_name; self.next_generated_name += 1; + // "4294967296" is 10 characters + let mut buffer: arrayvec::ArrayString<10> = arrayvec::ArrayString::new(); + + write!(buffer, "{}", index).unwrap(); + let ident = Ident(IdentStr::from_str(buffer.as_str())); + self.add(ident) }