Skip to content

Commit

Permalink
refactor(oxc): apply clippy::use_self
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Feb 19, 2025
1 parent 84f01a6 commit 88cad6f
Show file tree
Hide file tree
Showing 66 changed files with 914 additions and 1,052 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ iter_on_single_items = "warn"
unused_peekable = "warn"
too_long_first_doc_paragraph = "warn"
suspicious_operation_groupings = "warn"
use_self = "warn"
# cargo
cargo = { level = "warn", priority = -1 }
multiple_crate_versions = "allow"
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ where
}

impl<'alloc, T: Copy> CloneIn<'alloc> for Cell<T> {
type Cloned = Cell<T>;
type Cloned = Self;

fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned {
Cell::new(self.get())
Self::new(self.get())
}
}

Expand Down
12 changes: 6 additions & 6 deletions crates/oxc_allocator/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl<'alloc> String<'alloc> {
///
/// [`with_capacity_in`]: String::with_capacity_in
#[inline(always)]
pub fn new_in(allocator: &'alloc Allocator) -> String<'alloc> {
pub fn new_in(allocator: &'alloc Allocator) -> Self {
Self(ManuallyDrop::new(BumpaloString::new_in(allocator.bump())))
}

Expand All @@ -63,7 +63,7 @@ impl<'alloc> String<'alloc> {
/// [`capacity`]: String::capacity
/// [`new_in`]: String::new_in
#[inline(always)]
pub fn with_capacity_in(capacity: usize, allocator: &'alloc Allocator) -> String<'alloc> {
pub fn with_capacity_in(capacity: usize, allocator: &'alloc Allocator) -> Self {
Self(ManuallyDrop::new(BumpaloString::with_capacity_in(capacity, allocator.bump())))
}

Expand All @@ -79,15 +79,15 @@ impl<'alloc> String<'alloc> {
/// assert_eq!(s, "hello");
/// ```
#[inline(always)]
pub fn from_str_in(s: &str, allocator: &'alloc Allocator) -> String<'alloc> {
pub fn from_str_in(s: &str, allocator: &'alloc Allocator) -> Self {
Self(ManuallyDrop::new(BumpaloString::from_str_in(s, allocator.bump())))
}

/// Convert `Vec<u8>` into [`String`].
///
/// # Errors
/// Returns [`Err`] if the `Vec` does not comprise a valid UTF-8 string.
pub fn from_utf8(bytes: Vec<'alloc, u8>) -> Result<String<'alloc>, Utf8Error> {
pub fn from_utf8(bytes: Vec<'alloc, u8>) -> Result<Self, Utf8Error> {
// Check vec comprises a valid UTF-8 string.
from_utf8(&bytes)?;
// SAFETY: We just checked it's a valid UTF-8 string
Expand All @@ -105,7 +105,7 @@ impl<'alloc> String<'alloc> {
// `#[inline(always)]` because this is a no-op at runtime
#[expect(clippy::missing_safety_doc, clippy::unnecessary_safety_comment)]
#[inline(always)]
pub unsafe fn from_utf8_unchecked(bytes: Vec<'alloc, u8>) -> String<'alloc> {
pub unsafe fn from_utf8_unchecked(bytes: Vec<'alloc, u8>) -> Self {
// Cannot use `bumpalo::String::from_utf8_unchecked` because it takes a `bumpalo::collections::Vec`,
// and our inner `Vec` type is `allocator_api2::vec::Vec`.
// SAFETY: Conversion is safe because both types store data in arena in same way.
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<'alloc> String<'alloc> {
length: usize,
capacity: usize,
allocator: &'alloc Allocator,
) -> String<'alloc> {
) -> Self {
// SAFETY: Safety conditions of this method are the same as `BumpaloString`'s method
let inner = BumpaloString::from_raw_parts_in(buf, length, capacity, allocator.bump());
Self(ManuallyDrop::new(inner))
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ impl<'a> Expression<'a> {
///
/// For getting a reference to the expression inside, use [`Expression::get_inner_expression`].
#[must_use]
pub fn into_inner_expression(self) -> Expression<'a> {
pub fn into_inner_expression(self) -> Self {
let mut expr = self;
loop {
expr = match expr {
Expand All @@ -225,7 +225,7 @@ impl<'a> Expression<'a> {
///
/// For taking ownership of the expression inside, use [`Expression::into_inner_expression`].
/// For getting a mutable reference to the expression inside, use [`Expression::get_inner_expression_mut`].
pub fn get_inner_expression(&self) -> &Expression<'a> {
pub fn get_inner_expression(&self) -> &Self {
let mut expr = self;
loop {
expr = match expr {
Expand All @@ -248,7 +248,7 @@ impl<'a> Expression<'a> {
///
/// For taking ownership of the expression inside, use [`Expression::into_inner_expression`].
/// For getting an immutable reference to the expression inside, use [`Expression::get_inner_expression`].
pub fn get_inner_expression_mut(&mut self) -> &mut Expression<'a> {
pub fn get_inner_expression_mut(&mut self) -> &mut Self {
let mut expr = self;
loop {
expr = match expr {
Expand Down
8 changes: 4 additions & 4 deletions crates/oxc_ast/src/ast_impl/ts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl TSModuleDeclaration<'_> {
impl TSModuleDeclarationKind {
/// Returns `true` for `declare global { ... }`
pub fn is_global(self) -> bool {
matches!(self, TSModuleDeclarationKind::Global)
matches!(self, Self::Global)
}

/// Declaration keyword as a string, identical to how it would appear in the
Expand Down Expand Up @@ -304,9 +304,9 @@ impl TSTypeOperatorOperator {
/// Get the operator string as it would appear in the source code.
pub fn to_str(self) -> &'static str {
match self {
TSTypeOperatorOperator::Keyof => "keyof",
TSTypeOperatorOperator::Readonly => "readonly",
TSTypeOperatorOperator::Unique => "unique",
Self::Keyof => "keyof",
Self::Readonly => "readonly",
Self::Unique => "unique",
}
}
}
2 changes: 1 addition & 1 deletion crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/clone_in.rs`

#![allow(clippy::default_trait_access)]
#![allow(clippy::default_trait_access, clippy::use_self)]

use oxc_allocator::{Allocator, CloneIn};

Expand Down
Loading

0 comments on commit 88cad6f

Please sign in to comment.