refactor(ast, ast_tools): use full method path for generated derives trait calls. (#5462)

As of now if we remove the implementation of a trait for a type and implement the method on that type directly it wouldn't break while it isn't the original trait anymore so that method might do something entirely different.
This change is more explicit on trait calls so we hit compile errors on these kinds of changes.
This commit is contained in:
rzvxa 2024-09-05 05:36:50 +00:00
parent 90facd3657
commit ccc8a27e4f
13 changed files with 7107 additions and 6157 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -12,9 +12,9 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for RegularExpression<'old_allo
type Cloned = RegularExpression<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
RegularExpression {
span: self.span.clone_in(allocator),
pattern: self.pattern.clone_in(allocator),
flags: self.flags.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
pattern: CloneIn::clone_in(&self.pattern, allocator),
flags: CloneIn::clone_in(&self.flags, allocator),
}
}
}
@ -23,15 +23,15 @@ impl<'alloc> CloneIn<'alloc> for Flags {
type Cloned = Flags;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
Flags {
span: self.span.clone_in(allocator),
global: self.global.clone_in(allocator),
ignore_case: self.ignore_case.clone_in(allocator),
multiline: self.multiline.clone_in(allocator),
unicode: self.unicode.clone_in(allocator),
sticky: self.sticky.clone_in(allocator),
dot_all: self.dot_all.clone_in(allocator),
has_indices: self.has_indices.clone_in(allocator),
unicode_sets: self.unicode_sets.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
global: CloneIn::clone_in(&self.global, allocator),
ignore_case: CloneIn::clone_in(&self.ignore_case, allocator),
multiline: CloneIn::clone_in(&self.multiline, allocator),
unicode: CloneIn::clone_in(&self.unicode, allocator),
sticky: CloneIn::clone_in(&self.sticky, allocator),
dot_all: CloneIn::clone_in(&self.dot_all, allocator),
has_indices: CloneIn::clone_in(&self.has_indices, allocator),
unicode_sets: CloneIn::clone_in(&self.unicode_sets, allocator),
}
}
}
@ -39,21 +39,30 @@ impl<'alloc> CloneIn<'alloc> for Flags {
impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for Pattern<'old_alloc> {
type Cloned = Pattern<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Pattern { span: self.span.clone_in(allocator), body: self.body.clone_in(allocator) }
Pattern {
span: CloneIn::clone_in(&self.span, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for Disjunction<'old_alloc> {
type Cloned = Disjunction<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Disjunction { span: self.span.clone_in(allocator), body: self.body.clone_in(allocator) }
Disjunction {
span: CloneIn::clone_in(&self.span, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for Alternative<'old_alloc> {
type Cloned = Alternative<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Alternative { span: self.span.clone_in(allocator), body: self.body.clone_in(allocator) }
Alternative {
span: CloneIn::clone_in(&self.span, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -61,18 +70,26 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for Term<'old_alloc> {
type Cloned = Term<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
match self {
Self::BoundaryAssertion(it) => Term::BoundaryAssertion(it.clone_in(allocator)),
Self::LookAroundAssertion(it) => Term::LookAroundAssertion(it.clone_in(allocator)),
Self::Quantifier(it) => Term::Quantifier(it.clone_in(allocator)),
Self::Character(it) => Term::Character(it.clone_in(allocator)),
Self::Dot(it) => Term::Dot(it.clone_in(allocator)),
Self::CharacterClassEscape(it) => Term::CharacterClassEscape(it.clone_in(allocator)),
Self::UnicodePropertyEscape(it) => Term::UnicodePropertyEscape(it.clone_in(allocator)),
Self::CharacterClass(it) => Term::CharacterClass(it.clone_in(allocator)),
Self::CapturingGroup(it) => Term::CapturingGroup(it.clone_in(allocator)),
Self::IgnoreGroup(it) => Term::IgnoreGroup(it.clone_in(allocator)),
Self::IndexedReference(it) => Term::IndexedReference(it.clone_in(allocator)),
Self::NamedReference(it) => Term::NamedReference(it.clone_in(allocator)),
Self::BoundaryAssertion(it) => {
Term::BoundaryAssertion(CloneIn::clone_in(it, allocator))
}
Self::LookAroundAssertion(it) => {
Term::LookAroundAssertion(CloneIn::clone_in(it, allocator))
}
Self::Quantifier(it) => Term::Quantifier(CloneIn::clone_in(it, allocator)),
Self::Character(it) => Term::Character(CloneIn::clone_in(it, allocator)),
Self::Dot(it) => Term::Dot(CloneIn::clone_in(it, allocator)),
Self::CharacterClassEscape(it) => {
Term::CharacterClassEscape(CloneIn::clone_in(it, allocator))
}
Self::UnicodePropertyEscape(it) => {
Term::UnicodePropertyEscape(CloneIn::clone_in(it, allocator))
}
Self::CharacterClass(it) => Term::CharacterClass(CloneIn::clone_in(it, allocator)),
Self::CapturingGroup(it) => Term::CapturingGroup(CloneIn::clone_in(it, allocator)),
Self::IgnoreGroup(it) => Term::IgnoreGroup(CloneIn::clone_in(it, allocator)),
Self::IndexedReference(it) => Term::IndexedReference(CloneIn::clone_in(it, allocator)),
Self::NamedReference(it) => Term::NamedReference(CloneIn::clone_in(it, allocator)),
}
}
}
@ -81,8 +98,8 @@ impl<'alloc> CloneIn<'alloc> for BoundaryAssertion {
type Cloned = BoundaryAssertion;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
BoundaryAssertion {
span: self.span.clone_in(allocator),
kind: self.kind.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
kind: CloneIn::clone_in(&self.kind, allocator),
}
}
}
@ -103,9 +120,9 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for LookAroundAssertion<'old_al
type Cloned = LookAroundAssertion<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
LookAroundAssertion {
span: self.span.clone_in(allocator),
kind: self.kind.clone_in(allocator),
body: self.body.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
kind: CloneIn::clone_in(&self.kind, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -126,11 +143,11 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for Quantifier<'old_alloc> {
type Cloned = Quantifier<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
Quantifier {
span: self.span.clone_in(allocator),
min: self.min.clone_in(allocator),
max: self.max.clone_in(allocator),
greedy: self.greedy.clone_in(allocator),
body: self.body.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
min: CloneIn::clone_in(&self.min, allocator),
max: CloneIn::clone_in(&self.max, allocator),
greedy: CloneIn::clone_in(&self.greedy, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -139,9 +156,9 @@ impl<'alloc> CloneIn<'alloc> for Character {
type Cloned = Character;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
Character {
span: self.span.clone_in(allocator),
kind: self.kind.clone_in(allocator),
value: self.value.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
kind: CloneIn::clone_in(&self.kind, allocator),
value: CloneIn::clone_in(&self.value, allocator),
}
}
}
@ -166,8 +183,8 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassEscape {
type Cloned = CharacterClassEscape;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
CharacterClassEscape {
span: self.span.clone_in(allocator),
kind: self.kind.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
kind: CloneIn::clone_in(&self.kind, allocator),
}
}
}
@ -190,11 +207,11 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for UnicodePropertyEscape<'old_
type Cloned = UnicodePropertyEscape<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
UnicodePropertyEscape {
span: self.span.clone_in(allocator),
negative: self.negative.clone_in(allocator),
strings: self.strings.clone_in(allocator),
name: self.name.clone_in(allocator),
value: self.value.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
negative: CloneIn::clone_in(&self.negative, allocator),
strings: CloneIn::clone_in(&self.strings, allocator),
name: CloneIn::clone_in(&self.name, allocator),
value: CloneIn::clone_in(&self.value, allocator),
}
}
}
@ -202,7 +219,7 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for UnicodePropertyEscape<'old_
impl<'alloc> CloneIn<'alloc> for Dot {
type Cloned = Dot;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
Dot { span: self.span.clone_in(allocator) }
Dot { span: CloneIn::clone_in(&self.span, allocator) }
}
}
@ -210,10 +227,10 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for CharacterClass<'old_alloc>
type Cloned = CharacterClass<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
CharacterClass {
span: self.span.clone_in(allocator),
negative: self.negative.clone_in(allocator),
kind: self.kind.clone_in(allocator),
body: self.body.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
negative: CloneIn::clone_in(&self.negative, allocator),
kind: CloneIn::clone_in(&self.kind, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -234,20 +251,22 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for CharacterClassContents<'old
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
match self {
Self::CharacterClassRange(it) => {
CharacterClassContents::CharacterClassRange(it.clone_in(allocator))
CharacterClassContents::CharacterClassRange(CloneIn::clone_in(it, allocator))
}
Self::CharacterClassEscape(it) => {
CharacterClassContents::CharacterClassEscape(it.clone_in(allocator))
CharacterClassContents::CharacterClassEscape(CloneIn::clone_in(it, allocator))
}
Self::UnicodePropertyEscape(it) => {
CharacterClassContents::UnicodePropertyEscape(it.clone_in(allocator))
CharacterClassContents::UnicodePropertyEscape(CloneIn::clone_in(it, allocator))
}
Self::Character(it) => {
CharacterClassContents::Character(CloneIn::clone_in(it, allocator))
}
Self::Character(it) => CharacterClassContents::Character(it.clone_in(allocator)),
Self::NestedCharacterClass(it) => {
CharacterClassContents::NestedCharacterClass(it.clone_in(allocator))
CharacterClassContents::NestedCharacterClass(CloneIn::clone_in(it, allocator))
}
Self::ClassStringDisjunction(it) => {
CharacterClassContents::ClassStringDisjunction(it.clone_in(allocator))
CharacterClassContents::ClassStringDisjunction(CloneIn::clone_in(it, allocator))
}
}
}
@ -257,9 +276,9 @@ impl<'alloc> CloneIn<'alloc> for CharacterClassRange {
type Cloned = CharacterClassRange;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
CharacterClassRange {
span: self.span.clone_in(allocator),
min: self.min.clone_in(allocator),
max: self.max.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
min: CloneIn::clone_in(&self.min, allocator),
max: CloneIn::clone_in(&self.max, allocator),
}
}
}
@ -268,9 +287,9 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for ClassStringDisjunction<'old
type Cloned = ClassStringDisjunction<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
ClassStringDisjunction {
span: self.span.clone_in(allocator),
strings: self.strings.clone_in(allocator),
body: self.body.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
strings: CloneIn::clone_in(&self.strings, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -279,9 +298,9 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for ClassString<'old_alloc> {
type Cloned = ClassString<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
ClassString {
span: self.span.clone_in(allocator),
strings: self.strings.clone_in(allocator),
body: self.body.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
strings: CloneIn::clone_in(&self.strings, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -290,9 +309,9 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for CapturingGroup<'old_alloc>
type Cloned = CapturingGroup<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
CapturingGroup {
span: self.span.clone_in(allocator),
name: self.name.clone_in(allocator),
body: self.body.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
name: CloneIn::clone_in(&self.name, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -301,10 +320,10 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for IgnoreGroup<'old_alloc> {
type Cloned = IgnoreGroup<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
IgnoreGroup {
span: self.span.clone_in(allocator),
enabling_modifiers: self.enabling_modifiers.clone_in(allocator),
disabling_modifiers: self.disabling_modifiers.clone_in(allocator),
body: self.body.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
enabling_modifiers: CloneIn::clone_in(&self.enabling_modifiers, allocator),
disabling_modifiers: CloneIn::clone_in(&self.disabling_modifiers, allocator),
body: CloneIn::clone_in(&self.body, allocator),
}
}
}
@ -313,9 +332,9 @@ impl<'alloc> CloneIn<'alloc> for ModifierFlags {
type Cloned = ModifierFlags;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
ModifierFlags {
ignore_case: self.ignore_case.clone_in(allocator),
sticky: self.sticky.clone_in(allocator),
multiline: self.multiline.clone_in(allocator),
ignore_case: CloneIn::clone_in(&self.ignore_case, allocator),
sticky: CloneIn::clone_in(&self.sticky, allocator),
multiline: CloneIn::clone_in(&self.multiline, allocator),
}
}
}
@ -324,8 +343,8 @@ impl<'alloc> CloneIn<'alloc> for IndexedReference {
type Cloned = IndexedReference;
fn clone_in(&self, allocator: &'alloc Allocator) -> Self::Cloned {
IndexedReference {
span: self.span.clone_in(allocator),
index: self.index.clone_in(allocator),
span: CloneIn::clone_in(&self.span, allocator),
index: CloneIn::clone_in(&self.index, allocator),
}
}
}
@ -333,6 +352,9 @@ impl<'alloc> CloneIn<'alloc> for IndexedReference {
impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for NamedReference<'old_alloc> {
type Cloned = NamedReference<'new_alloc>;
fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned {
NamedReference { span: self.span.clone_in(allocator), name: self.name.clone_in(allocator) }
NamedReference {
span: CloneIn::clone_in(&self.span, allocator),
name: CloneIn::clone_in(&self.name, allocator),
}
}
}

View file

@ -1,6 +1,8 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/content_eq.rs`
#![allow(clippy::match_like_matches_macro)]
use oxc_span::cmp::ContentEq;
#[allow(clippy::wildcard_imports)]
@ -8,89 +10,100 @@ use crate::ast::*;
impl<'a> ContentEq for RegularExpression<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.pattern.content_eq(&other.pattern) && self.flags.content_eq(&other.flags)
ContentEq::content_eq(&self.pattern, &other.pattern)
&& ContentEq::content_eq(&self.flags, &other.flags)
}
}
impl ContentEq for Flags {
fn content_eq(&self, other: &Self) -> bool {
self.global.content_eq(&other.global)
&& self.ignore_case.content_eq(&other.ignore_case)
&& self.multiline.content_eq(&other.multiline)
&& self.unicode.content_eq(&other.unicode)
&& self.sticky.content_eq(&other.sticky)
&& self.dot_all.content_eq(&other.dot_all)
&& self.has_indices.content_eq(&other.has_indices)
&& self.unicode_sets.content_eq(&other.unicode_sets)
ContentEq::content_eq(&self.global, &other.global)
&& ContentEq::content_eq(&self.ignore_case, &other.ignore_case)
&& ContentEq::content_eq(&self.multiline, &other.multiline)
&& ContentEq::content_eq(&self.unicode, &other.unicode)
&& ContentEq::content_eq(&self.sticky, &other.sticky)
&& ContentEq::content_eq(&self.dot_all, &other.dot_all)
&& ContentEq::content_eq(&self.has_indices, &other.has_indices)
&& ContentEq::content_eq(&self.unicode_sets, &other.unicode_sets)
}
}
impl<'a> ContentEq for Pattern<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.body.content_eq(&other.body)
ContentEq::content_eq(&self.body, &other.body)
}
}
impl<'a> ContentEq for Disjunction<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.body.content_eq(&other.body)
ContentEq::content_eq(&self.body, &other.body)
}
}
impl<'a> ContentEq for Alternative<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.body.content_eq(&other.body)
ContentEq::content_eq(&self.body, &other.body)
}
}
impl<'a> ContentEq for Term<'a> {
fn content_eq(&self, other: &Self) -> bool {
match self {
Self::BoundaryAssertion(it) => {
matches!(other, Self::BoundaryAssertion(other) if it.content_eq(other))
}
Self::LookAroundAssertion(it) => {
matches!(other, Self::LookAroundAssertion(other) if it.content_eq(other))
}
Self::Quantifier(it) => {
matches!(other, Self::Quantifier(other) if it.content_eq(other))
}
Self::Character(it) => {
matches!(other, Self::Character(other) if it.content_eq(other))
}
Self::Dot(it) => matches!(other, Self::Dot(other) if it.content_eq(other)),
Self::CharacterClassEscape(it) => {
matches!(
other, Self::CharacterClassEscape(other) if it.content_eq(other)
)
}
Self::UnicodePropertyEscape(it) => {
matches!(
other, Self::UnicodePropertyEscape(other) if it.content_eq(other)
)
}
Self::CharacterClass(it) => {
matches!(other, Self::CharacterClass(other) if it.content_eq(other))
}
Self::CapturingGroup(it) => {
matches!(other, Self::CapturingGroup(other) if it.content_eq(other))
}
Self::IgnoreGroup(it) => {
matches!(other, Self::IgnoreGroup(other) if it.content_eq(other))
}
Self::IndexedReference(it) => {
matches!(other, Self::IndexedReference(other) if it.content_eq(other))
}
Self::NamedReference(it) => {
matches!(other, Self::NamedReference(other) if it.content_eq(other))
}
Self::BoundaryAssertion(it) => match other {
Self::BoundaryAssertion(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::LookAroundAssertion(it) => match other {
Self::LookAroundAssertion(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::Quantifier(it) => match other {
Self::Quantifier(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::Character(it) => match other {
Self::Character(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::Dot(it) => match other {
Self::Dot(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::CharacterClassEscape(it) => match other {
Self::CharacterClassEscape(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::UnicodePropertyEscape(it) => match other {
Self::UnicodePropertyEscape(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::CharacterClass(it) => match other {
Self::CharacterClass(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::CapturingGroup(it) => match other {
Self::CapturingGroup(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::IgnoreGroup(it) => match other {
Self::IgnoreGroup(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::IndexedReference(it) => match other {
Self::IndexedReference(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::NamedReference(it) => match other {
Self::NamedReference(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
}
}
}
impl ContentEq for BoundaryAssertion {
fn content_eq(&self, other: &Self) -> bool {
self.kind.content_eq(&other.kind)
ContentEq::content_eq(&self.kind, &other.kind)
}
}
@ -102,7 +115,8 @@ impl ContentEq for BoundaryAssertionKind {
impl<'a> ContentEq for LookAroundAssertion<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.kind.content_eq(&other.kind) && self.body.content_eq(&other.body)
ContentEq::content_eq(&self.kind, &other.kind)
&& ContentEq::content_eq(&self.body, &other.body)
}
}
@ -114,16 +128,17 @@ impl ContentEq for LookAroundAssertionKind {
impl<'a> ContentEq for Quantifier<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.min.content_eq(&other.min)
&& self.max.content_eq(&other.max)
&& self.greedy.content_eq(&other.greedy)
&& self.body.content_eq(&other.body)
ContentEq::content_eq(&self.min, &other.min)
&& ContentEq::content_eq(&self.max, &other.max)
&& ContentEq::content_eq(&self.greedy, &other.greedy)
&& ContentEq::content_eq(&self.body, &other.body)
}
}
impl ContentEq for Character {
fn content_eq(&self, other: &Self) -> bool {
self.kind.content_eq(&other.kind) && self.value.content_eq(&other.value)
ContentEq::content_eq(&self.kind, &other.kind)
&& ContentEq::content_eq(&self.value, &other.value)
}
}
@ -135,7 +150,7 @@ impl ContentEq for CharacterKind {
impl ContentEq for CharacterClassEscape {
fn content_eq(&self, other: &Self) -> bool {
self.kind.content_eq(&other.kind)
ContentEq::content_eq(&self.kind, &other.kind)
}
}
@ -147,10 +162,10 @@ impl ContentEq for CharacterClassEscapeKind {
impl<'a> ContentEq for UnicodePropertyEscape<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.negative.content_eq(&other.negative)
&& self.strings.content_eq(&other.strings)
&& self.name.content_eq(&other.name)
&& self.value.content_eq(&other.value)
ContentEq::content_eq(&self.negative, &other.negative)
&& ContentEq::content_eq(&self.strings, &other.strings)
&& ContentEq::content_eq(&self.name, &other.name)
&& ContentEq::content_eq(&self.value, &other.value)
}
}
@ -162,9 +177,9 @@ impl ContentEq for Dot {
impl<'a> ContentEq for CharacterClass<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.negative.content_eq(&other.negative)
&& self.kind.content_eq(&other.kind)
&& self.body.content_eq(&other.body)
ContentEq::content_eq(&self.negative, &other.negative)
&& ContentEq::content_eq(&self.kind, &other.kind)
&& ContentEq::content_eq(&self.body, &other.body)
}
}
@ -177,84 +192,85 @@ impl ContentEq for CharacterClassContentsKind {
impl<'a> ContentEq for CharacterClassContents<'a> {
fn content_eq(&self, other: &Self) -> bool {
match self {
Self::CharacterClassRange(it) => {
matches!(other, Self::CharacterClassRange(other) if it.content_eq(other))
}
Self::CharacterClassEscape(it) => {
matches!(
other, Self::CharacterClassEscape(other) if it.content_eq(other)
)
}
Self::UnicodePropertyEscape(it) => {
matches!(
other, Self::UnicodePropertyEscape(other) if it.content_eq(other)
)
}
Self::Character(it) => {
matches!(other, Self::Character(other) if it.content_eq(other))
}
Self::NestedCharacterClass(it) => {
matches!(
other, Self::NestedCharacterClass(other) if it.content_eq(other)
)
}
Self::ClassStringDisjunction(it) => {
matches!(
other, Self::ClassStringDisjunction(other) if it.content_eq(other)
)
}
Self::CharacterClassRange(it) => match other {
Self::CharacterClassRange(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::CharacterClassEscape(it) => match other {
Self::CharacterClassEscape(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::UnicodePropertyEscape(it) => match other {
Self::UnicodePropertyEscape(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::Character(it) => match other {
Self::Character(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::NestedCharacterClass(it) => match other {
Self::NestedCharacterClass(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
Self::ClassStringDisjunction(it) => match other {
Self::ClassStringDisjunction(other) if ContentEq::content_eq(it, other) => true,
_ => false,
},
}
}
}
impl ContentEq for CharacterClassRange {
fn content_eq(&self, other: &Self) -> bool {
self.min.content_eq(&other.min) && self.max.content_eq(&other.max)
ContentEq::content_eq(&self.min, &other.min) && ContentEq::content_eq(&self.max, &other.max)
}
}
impl<'a> ContentEq for ClassStringDisjunction<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.strings.content_eq(&other.strings) && self.body.content_eq(&other.body)
ContentEq::content_eq(&self.strings, &other.strings)
&& ContentEq::content_eq(&self.body, &other.body)
}
}
impl<'a> ContentEq for ClassString<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.strings.content_eq(&other.strings) && self.body.content_eq(&other.body)
ContentEq::content_eq(&self.strings, &other.strings)
&& ContentEq::content_eq(&self.body, &other.body)
}
}
impl<'a> ContentEq for CapturingGroup<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.name.content_eq(&other.name) && self.body.content_eq(&other.body)
ContentEq::content_eq(&self.name, &other.name)
&& ContentEq::content_eq(&self.body, &other.body)
}
}
impl<'a> ContentEq for IgnoreGroup<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.enabling_modifiers.content_eq(&other.enabling_modifiers)
&& self.disabling_modifiers.content_eq(&other.disabling_modifiers)
&& self.body.content_eq(&other.body)
ContentEq::content_eq(&self.enabling_modifiers, &other.enabling_modifiers)
&& ContentEq::content_eq(&self.disabling_modifiers, &other.disabling_modifiers)
&& ContentEq::content_eq(&self.body, &other.body)
}
}
impl ContentEq for ModifierFlags {
fn content_eq(&self, other: &Self) -> bool {
self.ignore_case.content_eq(&other.ignore_case)
&& self.sticky.content_eq(&other.sticky)
&& self.multiline.content_eq(&other.multiline)
ContentEq::content_eq(&self.ignore_case, &other.ignore_case)
&& ContentEq::content_eq(&self.sticky, &other.sticky)
&& ContentEq::content_eq(&self.multiline, &other.multiline)
}
}
impl ContentEq for IndexedReference {
fn content_eq(&self, other: &Self) -> bool {
self.index.content_eq(&other.index)
ContentEq::content_eq(&self.index, &other.index)
}
}
impl<'a> ContentEq for NamedReference<'a> {
fn content_eq(&self, other: &Self) -> bool {
self.name.content_eq(&other.name)
ContentEq::content_eq(&self.name, &other.name)
}
}

View file

@ -12,39 +12,39 @@ use crate::ast::*;
impl<'a> ContentHash for RegularExpression<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.pattern.content_hash(state);
self.flags.content_hash(state);
ContentHash::content_hash(&self.pattern, state);
ContentHash::content_hash(&self.flags, state);
}
}
impl ContentHash for Flags {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.global.content_hash(state);
self.ignore_case.content_hash(state);
self.multiline.content_hash(state);
self.unicode.content_hash(state);
self.sticky.content_hash(state);
self.dot_all.content_hash(state);
self.has_indices.content_hash(state);
self.unicode_sets.content_hash(state);
ContentHash::content_hash(&self.global, state);
ContentHash::content_hash(&self.ignore_case, state);
ContentHash::content_hash(&self.multiline, state);
ContentHash::content_hash(&self.unicode, state);
ContentHash::content_hash(&self.sticky, state);
ContentHash::content_hash(&self.dot_all, state);
ContentHash::content_hash(&self.has_indices, state);
ContentHash::content_hash(&self.unicode_sets, state);
}
}
impl<'a> ContentHash for Pattern<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.body.content_hash(state);
ContentHash::content_hash(&self.body, state);
}
}
impl<'a> ContentHash for Disjunction<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.body.content_hash(state);
ContentHash::content_hash(&self.body, state);
}
}
impl<'a> ContentHash for Alternative<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.body.content_hash(state);
ContentHash::content_hash(&self.body, state);
}
}
@ -52,25 +52,25 @@ impl<'a> ContentHash for Term<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
ContentHash::content_hash(&discriminant(self), state);
match self {
Self::BoundaryAssertion(it) => it.content_hash(state),
Self::LookAroundAssertion(it) => it.content_hash(state),
Self::Quantifier(it) => it.content_hash(state),
Self::Character(it) => it.content_hash(state),
Self::Dot(it) => it.content_hash(state),
Self::CharacterClassEscape(it) => it.content_hash(state),
Self::UnicodePropertyEscape(it) => it.content_hash(state),
Self::CharacterClass(it) => it.content_hash(state),
Self::CapturingGroup(it) => it.content_hash(state),
Self::IgnoreGroup(it) => it.content_hash(state),
Self::IndexedReference(it) => it.content_hash(state),
Self::NamedReference(it) => it.content_hash(state),
Self::BoundaryAssertion(it) => ContentHash::content_hash(it, state),
Self::LookAroundAssertion(it) => ContentHash::content_hash(it, state),
Self::Quantifier(it) => ContentHash::content_hash(it, state),
Self::Character(it) => ContentHash::content_hash(it, state),
Self::Dot(it) => ContentHash::content_hash(it, state),
Self::CharacterClassEscape(it) => ContentHash::content_hash(it, state),
Self::UnicodePropertyEscape(it) => ContentHash::content_hash(it, state),
Self::CharacterClass(it) => ContentHash::content_hash(it, state),
Self::CapturingGroup(it) => ContentHash::content_hash(it, state),
Self::IgnoreGroup(it) => ContentHash::content_hash(it, state),
Self::IndexedReference(it) => ContentHash::content_hash(it, state),
Self::NamedReference(it) => ContentHash::content_hash(it, state),
}
}
}
impl ContentHash for BoundaryAssertion {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.kind.content_hash(state);
ContentHash::content_hash(&self.kind, state);
}
}
@ -82,8 +82,8 @@ impl ContentHash for BoundaryAssertionKind {
impl<'a> ContentHash for LookAroundAssertion<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.kind.content_hash(state);
self.body.content_hash(state);
ContentHash::content_hash(&self.kind, state);
ContentHash::content_hash(&self.body, state);
}
}
@ -95,17 +95,17 @@ impl ContentHash for LookAroundAssertionKind {
impl<'a> ContentHash for Quantifier<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.min.content_hash(state);
self.max.content_hash(state);
self.greedy.content_hash(state);
self.body.content_hash(state);
ContentHash::content_hash(&self.min, state);
ContentHash::content_hash(&self.max, state);
ContentHash::content_hash(&self.greedy, state);
ContentHash::content_hash(&self.body, state);
}
}
impl ContentHash for Character {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.kind.content_hash(state);
self.value.content_hash(state);
ContentHash::content_hash(&self.kind, state);
ContentHash::content_hash(&self.value, state);
}
}
@ -117,7 +117,7 @@ impl ContentHash for CharacterKind {
impl ContentHash for CharacterClassEscape {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.kind.content_hash(state);
ContentHash::content_hash(&self.kind, state);
}
}
@ -129,10 +129,10 @@ impl ContentHash for CharacterClassEscapeKind {
impl<'a> ContentHash for UnicodePropertyEscape<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.negative.content_hash(state);
self.strings.content_hash(state);
self.name.content_hash(state);
self.value.content_hash(state);
ContentHash::content_hash(&self.negative, state);
ContentHash::content_hash(&self.strings, state);
ContentHash::content_hash(&self.name, state);
ContentHash::content_hash(&self.value, state);
}
}
@ -142,9 +142,9 @@ impl ContentHash for Dot {
impl<'a> ContentHash for CharacterClass<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.negative.content_hash(state);
self.kind.content_hash(state);
self.body.content_hash(state);
ContentHash::content_hash(&self.negative, state);
ContentHash::content_hash(&self.kind, state);
ContentHash::content_hash(&self.body, state);
}
}
@ -158,68 +158,68 @@ impl<'a> ContentHash for CharacterClassContents<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
ContentHash::content_hash(&discriminant(self), state);
match self {
Self::CharacterClassRange(it) => it.content_hash(state),
Self::CharacterClassEscape(it) => it.content_hash(state),
Self::UnicodePropertyEscape(it) => it.content_hash(state),
Self::Character(it) => it.content_hash(state),
Self::NestedCharacterClass(it) => it.content_hash(state),
Self::ClassStringDisjunction(it) => it.content_hash(state),
Self::CharacterClassRange(it) => ContentHash::content_hash(it, state),
Self::CharacterClassEscape(it) => ContentHash::content_hash(it, state),
Self::UnicodePropertyEscape(it) => ContentHash::content_hash(it, state),
Self::Character(it) => ContentHash::content_hash(it, state),
Self::NestedCharacterClass(it) => ContentHash::content_hash(it, state),
Self::ClassStringDisjunction(it) => ContentHash::content_hash(it, state),
}
}
}
impl ContentHash for CharacterClassRange {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.min.content_hash(state);
self.max.content_hash(state);
ContentHash::content_hash(&self.min, state);
ContentHash::content_hash(&self.max, state);
}
}
impl<'a> ContentHash for ClassStringDisjunction<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.strings.content_hash(state);
self.body.content_hash(state);
ContentHash::content_hash(&self.strings, state);
ContentHash::content_hash(&self.body, state);
}
}
impl<'a> ContentHash for ClassString<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.strings.content_hash(state);
self.body.content_hash(state);
ContentHash::content_hash(&self.strings, state);
ContentHash::content_hash(&self.body, state);
}
}
impl<'a> ContentHash for CapturingGroup<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.name.content_hash(state);
self.body.content_hash(state);
ContentHash::content_hash(&self.name, state);
ContentHash::content_hash(&self.body, state);
}
}
impl<'a> ContentHash for IgnoreGroup<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.enabling_modifiers.content_hash(state);
self.disabling_modifiers.content_hash(state);
self.body.content_hash(state);
ContentHash::content_hash(&self.enabling_modifiers, state);
ContentHash::content_hash(&self.disabling_modifiers, state);
ContentHash::content_hash(&self.body, state);
}
}
impl ContentHash for ModifierFlags {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.ignore_case.content_hash(state);
self.sticky.content_hash(state);
self.multiline.content_hash(state);
ContentHash::content_hash(&self.ignore_case, state);
ContentHash::content_hash(&self.sticky, state);
ContentHash::content_hash(&self.multiline, state);
}
}
impl ContentHash for IndexedReference {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.index.content_hash(state);
ContentHash::content_hash(&self.index, state);
}
}
impl<'a> ContentHash for NamedReference<'a> {
fn content_hash<H: Hasher>(&self, state: &mut H) {
self.name.content_hash(state);
ContentHash::content_hash(&self.name, state);
}
}

View file

@ -1,6 +1,8 @@
// Auto-generated code, DO NOT EDIT DIRECTLY!
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/content_eq.rs`
#![allow(clippy::match_like_matches_macro)]
use oxc_span::cmp::ContentEq;
#[allow(clippy::wildcard_imports)]

View file

@ -49,7 +49,7 @@ fn derive_enum(def: &EnumDef) -> TokenStream {
quote!(Self :: #ident => #ty_ident :: #ident)
} else {
used_alloc = true;
quote!(Self :: #ident(it) => #ty_ident :: #ident(it.clone_in(allocator)))
quote!(Self :: #ident(it) => #ty_ident :: #ident(CloneIn::clone_in(it, allocator)))
}
})
.collect_vec();
@ -74,7 +74,9 @@ fn derive_struct(def: &StructDef) -> TokenStream {
let ident = field.ident();
match field.markers.derive_attributes.clone_in {
CloneInAttribute::Default => quote!(#ident: Default::default()),
CloneInAttribute::None => quote!(#ident: self.#ident.clone_in(allocator)),
CloneInAttribute::None => {
quote!(#ident: CloneIn::clone_in(&self.#ident, allocator))
}
}
});
(format_ident!("allocator"), quote!(#ty_ident { #(#fields),* }))

View file

@ -39,6 +39,9 @@ impl Derive for DeriveContentEq {
fn prelude() -> TokenStream {
quote! {
// NOTE: writing long match expressions formats better than using `matches` macro.
#![allow(clippy::match_like_matches_macro)]
///@@line_break
use oxc_span::cmp::ContentEq;
}
@ -57,7 +60,11 @@ fn derive_enum(def: &EnumDef) -> (&str, TokenStream) {
} else {
quote! {
Self :: #ident(it) => {
matches!(other, Self :: #ident (other) if it.content_eq(other))
// NOTE: writing the match expression formats better than using `matches` macro.
match other {
Self :: #ident (other) if ContentEq::content_eq(it, other) => true,
_ => false,
}
}
}
}
@ -87,7 +94,7 @@ fn derive_struct(def: &StructDef) -> (&str, TokenStream) {
})
.map(|field| {
let ident = field.ident();
quote!(self.#ident.content_eq(&other.#ident))
quote!(ContentEq::content_eq(&self.#ident, &other.#ident))
})
.collect_vec();
if fields.is_empty() {

View file

@ -67,7 +67,7 @@ fn derive_enum(def: &EnumDef) -> (&str, TokenStream) {
non_exhaustive = true;
None
} else {
Some(quote!(Self :: #ident(it) => it.content_hash(state)))
Some(quote!(Self :: #ident(it) => ContentHash::content_hash(it, state)))
}
})
.collect_vec();
@ -98,7 +98,7 @@ fn derive_struct(def: &StructDef) -> (&str, TokenStream) {
})
.map(|field| {
let ident = field.ident();
quote!(self.#ident.content_hash(state);)
quote!(ContentHash::content_hash(&self.#ident, state);)
})
.collect_vec();
if fields.is_empty() {

View file

@ -5,7 +5,7 @@ use syn::Ident;
use crate::{
codegen::LateCtx,
schema::{EnumDef, GetGenerics, StructDef, ToType, TypeDef},
util::ToIdent,
util::{ToIdent, TypeWrapper},
};
use super::{define_derive, Derive, DeriveOutput};
@ -23,8 +23,19 @@ impl Derive for DeriveGetSpan {
let self_type = quote!(&self);
let result_type = quote!(Span);
let result_expr = quote!(self.span);
let unbox = |it| quote!(#it.as_ref());
let reference = |it| quote!(&#it);
derive(Self::trait_name(), "span", &self_type, &result_type, &result_expr, def)
derive(
Self::trait_name(),
"span",
&self_type,
&result_type,
&result_expr,
def,
unbox,
reference,
)
}
fn prelude() -> TokenStream {
@ -50,8 +61,19 @@ impl Derive for DeriveGetSpanMut {
let self_type = quote!(&mut self);
let result_type = quote!(&mut Span);
let result_expr = quote!(&mut self.span);
let unbox = |it| quote!(&mut **#it);
let reference = |it| quote!(&mut #it);
derive(Self::trait_name(), "span_mut", &self_type, &result_type, &result_expr, def)
derive(
Self::trait_name(),
"span_mut",
&self_type,
&result_type,
&result_expr,
def,
unbox,
reference,
)
}
fn prelude() -> TokenStream {
@ -64,37 +86,60 @@ impl Derive for DeriveGetSpanMut {
}
}
fn derive(
#[allow(clippy::too_many_arguments)]
fn derive<U, R>(
trait_name: &str,
method_name: &str,
self_type: &TokenStream,
result_type: &TokenStream,
result_expr: &TokenStream,
def: &TypeDef,
) -> TokenStream {
unbox: U,
reference: R,
) -> TokenStream
where
U: Fn(TokenStream) -> TokenStream,
R: Fn(TokenStream) -> TokenStream,
{
let trait_ident = trait_name.to_ident();
let method_ident = method_name.to_ident();
match &def {
TypeDef::Enum(def) => derive_enum(def, &trait_ident, &method_ident, self_type, result_type),
TypeDef::Struct(def) => {
derive_struct(def, &trait_ident, &method_ident, self_type, result_type, result_expr)
TypeDef::Enum(def) => {
derive_enum(def, &trait_ident, &method_ident, self_type, result_type, unbox)
}
TypeDef::Struct(def) => derive_struct(
def,
&trait_ident,
&method_ident,
self_type,
result_type,
result_expr,
reference,
),
}
}
fn derive_enum(
fn derive_enum<U>(
def: &EnumDef,
trait_name: &Ident,
method_name: &Ident,
self_type: &TokenStream,
result_type: &TokenStream,
) -> TokenStream {
unbox: U,
) -> TokenStream
where
U: Fn(TokenStream) -> TokenStream,
{
let target_type = def.to_type();
let generics = def.generics();
let matches = def.all_variants().map(|var| {
let ident = var.ident();
quote!(Self :: #ident(it) => it.#method_name())
let mut it = quote!(it);
if var.fields.first().is_some_and(|it| it.typ.analysis().wrapper == TypeWrapper::Box) {
it = unbox(it);
}
quote!(Self :: #ident(it) => #trait_name :: #method_name(#it))
});
quote! {
@ -108,21 +153,26 @@ fn derive_enum(
}
}
fn derive_struct(
fn derive_struct<R>(
def: &StructDef,
trait_name: &Ident,
method_name: &Ident,
self_type: &TokenStream,
result_type: &TokenStream,
result_expr: &TokenStream,
) -> TokenStream {
reference: R,
) -> TokenStream
where
R: Fn(TokenStream) -> TokenStream,
{
let target_type = def.to_type();
let generics = def.generics();
let span_field = def.fields.iter().find(|field| field.markers.span);
let result_expr = if let Some(span_field) = span_field {
let ident = span_field.name.as_ref().map(ToIdent::to_ident).unwrap();
quote!(self.#ident.#method_name())
let reference = reference(quote!(self.#ident));
quote!(#trait_name :: #method_name (#reference))
} else {
result_expr.clone()
};