Skip to content

Commit

Permalink
chore: Rust v1.83.0 changes (#7535)
Browse files Browse the repository at this point in the history
This PR does not upgrade rustc. Only changes are applied.

We cannot upgrade to the lastet Rust version yet due to wasm-bindgen
breaking some generated types.

THere's also some elided lifetimes in `**/generated/**`, which requires
modification to ast tools.
  • Loading branch information
Boshen authored Nov 29, 2024
1 parent 18e3964 commit d942a8d
Show file tree
Hide file tree
Showing 95 changed files with 492 additions and 493 deletions.
2 changes: 1 addition & 1 deletion crates/oxc_allocator/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub trait GetAddress {
fn address(&self) -> Address;
}

impl<'a, T> GetAddress for Box<'a, T> {
impl<T> GetAddress for Box<'_, T> {
/// Get the memory address of a value allocated in the arena.
///
/// AST nodes in a `Box` in an arena are guaranteed to never move in memory,
Expand Down
20 changes: 10 additions & 10 deletions crates/oxc_allocator/src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::Allocator;
/// being called to guarantee soundness.
pub struct Box<'alloc, T: ?Sized>(NonNull<T>, PhantomData<(&'alloc (), T)>);

impl<'alloc, T> Box<'alloc, T> {
impl<T> Box<'_, T> {
/// Take ownership of the value stored in this [`Box`], consuming the box in
/// the process.
///
Expand Down Expand Up @@ -56,7 +56,7 @@ impl<'alloc, T> Box<'alloc, T> {
}
}

impl<'alloc, T> Box<'alloc, T> {
impl<T> Box<'_, T> {
/// Put a `value` into a memory arena and get back a [`Box`] with ownership
/// to the allocation.
///
Expand All @@ -82,7 +82,7 @@ impl<'alloc, T> Box<'alloc, T> {
}
}

impl<'alloc, T: ?Sized> Box<'alloc, T> {
impl<T: ?Sized> Box<'_, T> {
/// Create a [`Box`] from a raw pointer to a value.
///
/// The [`Box`] takes ownership of the data pointed to by `ptr`.
Expand All @@ -108,7 +108,7 @@ impl<'alloc, T: ?Sized> Box<'alloc, T> {
}
}

impl<'alloc, T: ?Sized> ops::Deref for Box<'alloc, T> {
impl<T: ?Sized> ops::Deref for Box<'_, T> {
type Target = T;

fn deref(&self) -> &T {
Expand All @@ -117,26 +117,26 @@ impl<'alloc, T: ?Sized> ops::Deref for Box<'alloc, T> {
}
}

impl<'alloc, T: ?Sized> ops::DerefMut for Box<'alloc, T> {
impl<T: ?Sized> ops::DerefMut for Box<'_, T> {
fn deref_mut(&mut self) -> &mut T {
// SAFETY: self.0 is always a unique reference allocated from a Bump in Box::new_in
unsafe { self.0.as_mut() }
}
}

impl<'alloc, T: ?Sized> AsRef<T> for Box<'alloc, T> {
impl<T: ?Sized> AsRef<T> for Box<'_, T> {
fn as_ref(&self) -> &T {
self
}
}

impl<'alloc, T: ?Sized> AsMut<T> for Box<'alloc, T> {
impl<T: ?Sized> AsMut<T> for Box<'_, T> {
fn as_mut(&mut self) -> &mut T {
self
}
}

impl<'alloc, T: ?Sized + Debug> Debug for Box<'alloc, T> {
impl<T: ?Sized + Debug> Debug for Box<'_, T> {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
self.deref().fmt(f)
}
Expand All @@ -153,7 +153,7 @@ impl<'alloc, T: ?Sized + Debug> Debug for Box<'alloc, T> {
// }

#[cfg(any(feature = "serialize", test))]
impl<'alloc, T> Serialize for Box<'alloc, T>
impl<T> Serialize for Box<'_, T>
where
T: Serialize,
{
Expand All @@ -165,7 +165,7 @@ where
}
}

impl<'alloc, T: Hash> Hash for Box<'alloc, T> {
impl<T: Hash> Hash for Box<'_, T> {
fn hash<H: Hasher>(&self, state: &mut H) {
self.deref().hash(state);
}
Expand Down
6 changes: 3 additions & 3 deletions crates/oxc_allocator/src/clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
}
}

impl<'old_alloc, 'new_alloc, T, C> CloneIn<'new_alloc> for Box<'old_alloc, T>
impl<'new_alloc, T, C> CloneIn<'new_alloc> for Box<'_, T>
where
T: CloneIn<'new_alloc, Cloned = C>,
{
Expand All @@ -52,7 +52,7 @@ where
}
}

impl<'old_alloc, 'new_alloc, T, C> CloneIn<'new_alloc> for Vec<'old_alloc, T>
impl<'new_alloc, T, C> CloneIn<'new_alloc> for Vec<'_, T>
where
T: CloneIn<'new_alloc, Cloned = C>,
{
Expand All @@ -71,7 +71,7 @@ impl<'alloc, T: Copy> CloneIn<'alloc> for Cell<T> {
}
}

impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for &'old_alloc str {
impl<'new_alloc> CloneIn<'new_alloc> for &str {
type Cloned = &'new_alloc str;

fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_allocator/src/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,22 +215,22 @@ impl<'alloc, T> IntoIterator for &'alloc Vec<'alloc, T> {
}
}

impl<'alloc, T> ops::Index<usize> for Vec<'alloc, T> {
impl<T> ops::Index<usize> for Vec<'_, T> {
type Output = T;

fn index(&self, index: usize) -> &Self::Output {
self.0.index(index)
}
}

impl<'alloc, T> ops::IndexMut<usize> for Vec<'alloc, T> {
impl<T> ops::IndexMut<usize> for Vec<'_, T> {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
self.0.index_mut(index)
}
}

#[cfg(any(feature = "serialize", test))]
impl<'alloc, T> Serialize for Vec<'alloc, T>
impl<T> Serialize for Vec<'_, T>
where
T: Serialize,
{
Expand All @@ -246,15 +246,15 @@ where
}
}

impl<'alloc, T: Hash> Hash for Vec<'alloc, T> {
impl<T: Hash> Hash for Vec<'_, T> {
fn hash<H: Hasher>(&self, state: &mut H) {
for e in self.0.iter() {
e.hash(state);
}
}
}

impl<'alloc, T: Debug> Debug for Vec<'alloc, T> {
impl<T: Debug> Debug for Vec<'_, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let inner = &*self.0;
f.debug_tuple("Vec").field(inner).finish()
Expand Down
50 changes: 25 additions & 25 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use oxc_syntax::{operator::UnaryOperator, scope::ScopeFlags, symbol::SymbolId};

use crate::ast::*;

impl<'a> Program<'a> {
impl Program<'_> {
/// Returns `true` if this program has no statements or directives.
pub fn is_empty(&self) -> bool {
self.body.is_empty() && self.directives.is_empty()
Expand Down Expand Up @@ -284,34 +284,34 @@ impl<'a> Expression<'a> {
}
}

impl<'a> fmt::Display for IdentifierName<'a> {
impl fmt::Display for IdentifierName<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
self.name.fmt(f)
}
}

impl<'a> fmt::Display for IdentifierReference<'a> {
impl fmt::Display for IdentifierReference<'_> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.name.fmt(f)
}
}

impl<'a> fmt::Display for BindingIdentifier<'a> {
impl fmt::Display for BindingIdentifier<'_> {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.name.fmt(f)
}
}

impl<'a> ArrayExpressionElement<'a> {
impl ArrayExpressionElement<'_> {
#[allow(missing_docs)]
pub fn is_elision(&self) -> bool {
matches!(self, Self::Elision(_))
}
}

impl<'a> ObjectPropertyKind<'a> {
impl ObjectPropertyKind<'_> {
/// Returns `true` if this object property is a [spread](SpreadElement).
#[inline]
pub fn is_spread(&self) -> bool {
Expand Down Expand Up @@ -544,7 +544,7 @@ impl<'a> ChainElement<'a> {
}
}

impl<'a> CallExpression<'a> {
impl CallExpression<'_> {
#[allow(missing_docs)]
pub fn callee_name(&self) -> Option<&str> {
match &self.callee {
Expand Down Expand Up @@ -684,7 +684,7 @@ impl<'a> ObjectAssignmentTarget<'a> {
}
}

impl<'a> AssignmentTargetMaybeDefault<'a> {
impl AssignmentTargetMaybeDefault<'_> {
#[allow(missing_docs)]
pub fn name(&self) -> Option<Atom> {
match self {
Expand All @@ -701,7 +701,7 @@ impl<'a> AssignmentTargetMaybeDefault<'a> {
}
}

impl<'a> Statement<'a> {
impl Statement<'_> {
#[allow(missing_docs)]
pub fn is_typescript_syntax(&self) -> bool {
match self {
Expand Down Expand Up @@ -737,7 +737,7 @@ impl<'a> FromIn<'a, Expression<'a>> for Statement<'a> {
}
}

impl<'a> Directive<'a> {
impl Directive<'_> {
/// A Use Strict Directive is an ExpressionStatement in a Directive Prologue whose StringLiteral is either of the exact code point sequences "use strict" or 'use strict'.
/// A Use Strict Directive may not contain an EscapeSequence or LineContinuation.
/// <https://tc39.es/ecma262/#sec-directive-prologues-and-the-use-strict-directive>
Expand Down Expand Up @@ -791,7 +791,7 @@ impl<'a> Declaration<'a> {
}
}

impl<'a> VariableDeclaration<'a> {
impl VariableDeclaration<'_> {
#[allow(missing_docs)]
pub fn is_typescript_syntax(&self) -> bool {
self.declare
Expand Down Expand Up @@ -843,23 +843,23 @@ impl fmt::Display for VariableDeclarationKind {
}
}

impl<'a> ForStatementInit<'a> {
impl ForStatementInit<'_> {
/// LexicalDeclaration[In, Yield, Await] :
/// LetOrConst BindingList[?In, ?Yield, ?Await] ;
pub fn is_lexical_declaration(&self) -> bool {
matches!(self, Self::VariableDeclaration(decl) if decl.kind.is_lexical())
}
}

impl<'a> ForStatementLeft<'a> {
impl ForStatementLeft<'_> {
/// LexicalDeclaration[In, Yield, Await] :
/// LetOrConst BindingList[?In, ?Yield, ?Await] ;
pub fn is_lexical_declaration(&self) -> bool {
matches!(self, Self::VariableDeclaration(decl) if decl.kind.is_lexical())
}
}

impl<'a> SwitchCase<'a> {
impl SwitchCase<'_> {
/// `true` for `default:` cases.
pub fn is_default_case(&self) -> bool {
self.test.is_none()
Expand Down Expand Up @@ -927,7 +927,7 @@ impl<'a> BindingPatternKind<'a> {
}
}

impl<'a> ObjectPattern<'a> {
impl ObjectPattern<'_> {
/// `true` for empty object patterns (`{}`).
pub fn is_empty(&self) -> bool {
self.properties.is_empty() && self.rest.is_none()
Expand All @@ -939,7 +939,7 @@ impl<'a> ObjectPattern<'a> {
}
}

impl<'a> ArrayPattern<'a> {
impl ArrayPattern<'_> {
/// `true` for empty array patterns (`[]`).
pub fn is_empty(&self) -> bool {
self.elements.is_empty() && self.rest.is_none()
Expand Down Expand Up @@ -1016,7 +1016,7 @@ impl<'a> FormalParameters<'a> {
}
}

impl<'a> FormalParameter<'a> {
impl FormalParameter<'_> {
/// `true` if a `public` accessibility modifier is present. Use
/// [`has_modifier`](FormalParameter::has_modifier) if you want to check for
/// _any_ modifier, including `readonly` and `override`.
Expand Down Expand Up @@ -1060,7 +1060,7 @@ impl FormalParameterKind {
}
}

impl<'a> FormalParameters<'a> {
impl FormalParameters<'_> {
/// `true` if no parameters are bound.
pub fn is_empty(&self) -> bool {
self.items.is_empty()
Expand All @@ -1072,7 +1072,7 @@ impl<'a> FormalParameters<'a> {
}
}

impl<'a> FunctionBody<'a> {
impl FunctionBody<'_> {
/// `true` if this function body contains no statements or directives.
pub fn is_empty(&self) -> bool {
self.directives.is_empty() && self.statements.is_empty()
Expand All @@ -1097,7 +1097,7 @@ impl<'a> ArrowFunctionExpression<'a> {
}
}

impl<'a> Class<'a> {
impl Class<'_> {
/// `true` if this [`Class`] is an expression.
///
/// For example,
Expand Down Expand Up @@ -1412,29 +1412,29 @@ impl<'a> ImportAttributeKey<'a> {
}
}

impl<'a> ExportNamedDeclaration<'a> {
impl ExportNamedDeclaration<'_> {
#[allow(missing_docs)]
pub fn is_typescript_syntax(&self) -> bool {
self.export_kind == ImportOrExportKind::Type
|| self.declaration.as_ref().map_or(false, Declaration::is_typescript_syntax)
}
}

impl<'a> ExportDefaultDeclaration<'a> {
impl ExportDefaultDeclaration<'_> {
#[allow(missing_docs)]
pub fn is_typescript_syntax(&self) -> bool {
self.declaration.is_typescript_syntax()
}
}

impl<'a> ExportAllDeclaration<'a> {
impl ExportAllDeclaration<'_> {
#[allow(missing_docs)]
pub fn is_typescript_syntax(&self) -> bool {
self.export_kind.is_type()
}
}

impl<'a> ExportDefaultDeclarationKind<'a> {
impl ExportDefaultDeclarationKind<'_> {
#[allow(missing_docs)]
#[inline]
pub fn is_typescript_syntax(&self) -> bool {
Expand All @@ -1447,7 +1447,7 @@ impl<'a> ExportDefaultDeclarationKind<'a> {
}
}

impl<'a> fmt::Display for ModuleExportName<'a> {
impl fmt::Display for ModuleExportName<'_> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let s = match self {
Self::IdentifierName(identifier) => identifier.name.to_string(),
Expand Down
Loading

0 comments on commit d942a8d

Please sign in to comment.