mirror of
https://github.com/oxc-project/oxc.git
synced 2026-11-04 10:29:58 +00:00
refactor(syntax): move CloneIn impls (#10571)
Pure refactor. Move `CloneIn` impls lower down. It's conventional to have core methods before trait impls.
This commit is contained in:
1 parent
66e384cfd3
commit
d22c1aeafd
3 files changed
+43
-43
No files matched your search
@@ -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<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
|
||||
@@ -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<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
|
||||
@@ -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<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
||||
|
||||
Reference in new issue
Block a user