diff --git a/crates/oxc_syntax/src/reference.rs b/crates/oxc_syntax/src/reference.rs index 5d8c1cbcde800..9743352d82401 100644 --- a/crates/oxc_syntax/src/reference.rs +++ b/crates/oxc_syntax/src/reference.rs @@ -19,6 +19,19 @@ use oxc_ast_macros::ast; #[estree(skip)] pub struct ReferenceId(NonMaxU32); +impl Idx for ReferenceId { + #[expect(clippy::cast_possible_truncation)] + fn from_usize(idx: usize) -> Self { + assert!(idx < u32::MAX as usize); + // SAFETY: We just checked `idx` is a legal value for `NonMaxU32` + Self(unsafe { NonMaxU32::new_unchecked(idx as u32) }) + } + + fn index(self) -> usize { + self.0.get() as usize + } +} + impl<'alloc> CloneIn<'alloc> for ReferenceId { type Cloned = Self; @@ -34,19 +47,6 @@ impl<'alloc> CloneIn<'alloc> for ReferenceId { } } -impl Idx for ReferenceId { - #[expect(clippy::cast_possible_truncation)] - fn from_usize(idx: usize) -> Self { - assert!(idx < u32::MAX as usize); - // SAFETY: We just checked `idx` is a legal value for `NonMaxU32` - Self(unsafe { NonMaxU32::new_unchecked(idx as u32) }) - } - - fn index(self) -> usize { - self.0.get() as usize - } -} - #[cfg(feature = "serialize")] impl Serialize for ReferenceId { fn serialize(&self, serializer: S) -> Result { diff --git a/crates/oxc_syntax/src/scope.rs b/crates/oxc_syntax/src/scope.rs index c982fb358c395..2786d6508a416 100644 --- a/crates/oxc_syntax/src/scope.rs +++ b/crates/oxc_syntax/src/scope.rs @@ -16,21 +16,6 @@ use oxc_ast_macros::ast; #[estree(skip)] pub struct ScopeId(NonMaxU32); -impl<'alloc> CloneIn<'alloc> for ScopeId { - type Cloned = Self; - - fn clone_in(&self, _: &'alloc Allocator) -> Self { - // `clone_in` should never reach this, because `CloneIn` skips scope_id field - unreachable!(); - } - - #[expect(clippy::inline_always)] - #[inline(always)] - fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self { - *self - } -} - impl ScopeId { /// Create `ScopeId` from `u32`. /// @@ -66,6 +51,21 @@ impl Idx for ScopeId { } } +impl<'alloc> CloneIn<'alloc> for ScopeId { + type Cloned = Self; + + fn clone_in(&self, _: &'alloc Allocator) -> Self { + // `clone_in` should never reach this, because `CloneIn` skips scope_id field + unreachable!(); + } + + #[expect(clippy::inline_always)] + #[inline(always)] + fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self { + *self + } +} + #[cfg(feature = "serialize")] impl Serialize for ScopeId { fn serialize(&self, serializer: S) -> Result { diff --git a/crates/oxc_syntax/src/symbol.rs b/crates/oxc_syntax/src/symbol.rs index 333d4fe318d91..f6a5d8f896e8f 100644 --- a/crates/oxc_syntax/src/symbol.rs +++ b/crates/oxc_syntax/src/symbol.rs @@ -16,21 +16,6 @@ use oxc_ast_macros::ast; #[estree(skip)] pub struct SymbolId(NonMaxU32); -impl<'alloc> CloneIn<'alloc> for SymbolId { - type Cloned = Self; - - fn clone_in(&self, _: &'alloc Allocator) -> Self { - // `clone_in` should never reach this, because `CloneIn` skips symbol_id field - unreachable!(); - } - - #[expect(clippy::inline_always)] - #[inline(always)] - fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self { - *self - } -} - impl SymbolId { /// Create `SymbolId` from `u32`. /// @@ -66,6 +51,21 @@ impl Idx for SymbolId { } } +impl<'alloc> CloneIn<'alloc> for SymbolId { + type Cloned = Self; + + fn clone_in(&self, _: &'alloc Allocator) -> Self { + // `clone_in` should never reach this, because `CloneIn` skips symbol_id field + unreachable!(); + } + + #[expect(clippy::inline_always)] + #[inline(always)] + fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self { + *self + } +} + #[cfg(feature = "serialize")] impl Serialize for SymbolId { fn serialize(&self, serializer: S) -> Result {