Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 13 additions & 13 deletions crates/oxc_syntax/src/reference.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
Expand Down
30 changes: 15 additions & 15 deletions crates/oxc_syntax/src/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -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<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
Expand Down
30 changes: 15 additions & 15 deletions crates/oxc_syntax/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
///
Expand Down Expand Up @@ -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<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
Expand Down
Loading