Skip to content

Commit

Permalink
Removed Extra Traits Syn Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
Redfire75369 committed Nov 25, 2023
1 parent 3b59e0a commit eb6fbe3
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion ion-proc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ proc-macro2 = "1.0.69"

[dependencies.syn]
version = "2.0.39"
features = ["extra-traits", "full", "visit-mut"]
features = ["full", "visit-mut"]

[lints]
workspace = true
Expand Down
7 changes: 1 addition & 6 deletions ion-proc/src/attribute/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod keywords {
custom_keyword!(set);
}

#[derive(Clone, Debug)]
#[derive(Clone)]
pub(crate) enum Name {
String(LitStr),
Symbol(ExprPath),
Expand Down Expand Up @@ -67,7 +67,6 @@ impl Parse for Name {
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct NameAttribute {
kw: keywords::name,
eq: Token![=],
Expand All @@ -90,7 +89,6 @@ impl Parse for NameAttribute {
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct ClassNameAttribute {
kw: keywords::name,
eq: Token![=],
Expand All @@ -113,7 +111,6 @@ impl Parse for ClassNameAttribute {
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct AliasAttribute {
kw: keywords::alias,
eq: Token![=],
Expand Down Expand Up @@ -141,7 +138,6 @@ impl Parse for AliasAttribute {

// TODO: Add `inspectable` to provide `toString` and `toJSON`
#[allow(dead_code)]
#[derive(Debug)]
pub(crate) enum ClassAttribute {
Name(ClassNameAttribute),
Class(keywords::class),
Expand All @@ -162,7 +158,6 @@ impl Parse for ClassAttribute {
}
}

#[derive(Debug)]
pub(crate) enum MethodAttribute {
Name(NameAttribute),
Alias(AliasAttribute),
Expand Down
2 changes: 0 additions & 2 deletions ion-proc/src/attribute/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ mod keywords {
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) struct ConvertAttribute {
kw: keywords::convert,
eq: Token![=],
Expand All @@ -37,7 +36,6 @@ impl Parse for ConvertAttribute {
}
}

#[derive(Debug)]
pub(crate) enum ParameterAttribute {
This(keywords::this),
VarArgs(keywords::varargs),
Expand Down
1 change: 0 additions & 1 deletion ion-proc/src/class/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::attribute::class::Name;
use crate::class::method::{impl_method, Method};
use crate::function::parameters::{Parameter, Parameters};

#[derive(Debug)]
pub(super) struct Accessor(pub(super) Option<Method>, Option<Method>);

impl Accessor {
Expand Down
3 changes: 1 addition & 2 deletions ion-proc/src/class/impl/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::class::accessor::{Accessor, flatten_accessors};
use crate::class::method::Method;
use crate::class::property::Property;

#[derive(Debug, Default)]
#[derive(Default)]
pub(super) struct PrototypeSpecs {
pub(super) methods: (Vec<Method>, Vec<Method>),
pub(super) properties: (Vec<Property>, Vec<Property>),
Expand Down Expand Up @@ -50,7 +50,6 @@ impl PrototypeSpecs {
}
}

#[derive(Debug)]
pub(super) struct SpecFunctions {
methods: (ImplItemFn, ImplItemFn),
properties: (ImplItemFn, ImplItemFn),
Expand Down
2 changes: 1 addition & 1 deletion ion-proc/src/class/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub(super) enum MethodReceiver {
Static,
}

#[derive(Clone, Debug)]
#[derive(Clone)]
pub(super) struct Method {
pub(super) receiver: MethodReceiver,
pub(super) method: ItemFn,
Expand Down
2 changes: 1 addition & 1 deletion ion-proc/src/class/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub(super) enum PropertyType {
String,
}

#[derive(Clone, Debug)]
#[derive(Clone)]
pub(super) struct Property {
pub(super) ty: PropertyType,
pub(super) ident: Ident,
Expand Down
10 changes: 4 additions & 6 deletions ion-proc/src/function/parameters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ use syn::spanned::Spanned;
use syn::visit_mut::visit_type_mut;

use crate::attribute::function::ParameterAttribute;
use crate::utils::{format_pat, path_ends_with};
use crate::utils::{format_pat, path_ends_with, pat_is_ident};
use crate::visitors::{LifetimeRemover, SelfRenamer};

#[derive(Debug)]
pub(crate) enum Parameter {
Regular {
pat: Box<Pat>,
Expand All @@ -34,14 +33,13 @@ pub(crate) enum Parameter {
Arguments(Box<Pat>, Box<Type>),
}

#[derive(Clone, Debug, PartialEq)]
#[derive(Clone)]
pub(crate) enum ThisKind {
Ref(Option<Lifetime>, Option<Token![mut]>),
Object(Option<Lifetime>, Option<Token![mut]>),
Owned,
}

#[derive(Debug)]
pub(crate) struct ThisParameter {
pat: Box<Pat>,
ty: Box<Type>,
Expand Down Expand Up @@ -152,7 +150,7 @@ impl ThisParameter {
let span = pat_ty.span();
let PatType { pat, mut ty, .. } = pat_ty.clone();
match class_ty {
Some(class_ty) if pat == parse_quote!(self) => {
Some(class_ty) if pat_is_ident(&pat, "self") => {
visit_type_mut(&mut SelfRenamer { ty: class_ty }, &mut ty);
parse_this(pat, ty, true, span).map(Some)
}
Expand Down Expand Up @@ -195,7 +193,7 @@ impl ThisParameter {
pub(crate) fn to_statement(&self, ion: &TokenStream, is_class: bool) -> Result<Stmt> {
let ThisParameter { pat, ty, kind } = self;
let self_ = parse_quote!(self_);
let pat = if is_class && **pat == parse_quote!(self) {
let pat = if is_class && pat_is_ident(pat, "self") {
&self_
} else {
pat
Expand Down
11 changes: 11 additions & 0 deletions ion-proc/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ where
}
}

pub(crate) fn pat_is_ident<I: ?Sized>(pat: &Pat, ident: &I) -> bool
where
Ident: PartialEq<I>,
{
if let Pat::Ident(pat) = pat {
&pat.ident == ident
} else {
false
}
}

pub(crate) fn add_trait_bounds(generics: &mut Generics, bound: &TypeParamBound) {
for param in &mut generics.params {
if let GenericParam::Type(type_param) = param {
Expand Down
6 changes: 1 addition & 5 deletions ion-proc/src/value/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod keywords {
}

#[allow(dead_code)]
#[derive(Clone, Debug)]
#[derive(Clone)]
pub(crate) enum Tag {
Untagged(keywords::untagged),
External(keywords::tag),
Expand Down Expand Up @@ -57,7 +57,6 @@ impl Parse for Tag {
}
}

#[derive(Debug)]
pub(crate) enum DefaultValue {
Literal(Lit),
Closure(ExprClosure),
Expand All @@ -75,7 +74,6 @@ impl Parse for DefaultValue {
}
}

#[derive(Debug)]
pub(crate) enum DataAttribute {
Tag(Tag),
Inherit(keywords::inherit),
Expand All @@ -97,7 +95,6 @@ impl Parse for DataAttribute {
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) enum VariantAttribute {
Tag(Tag),
Inherit(keywords::inherit),
Expand All @@ -122,7 +119,6 @@ impl Parse for VariantAttribute {
}

#[allow(dead_code)]
#[derive(Debug)]
pub(crate) enum FieldAttribute {
Name {
kw: keywords::name,
Expand Down
8 changes: 6 additions & 2 deletions ion-proc/src/visitors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use syn::{GenericArgument, PathArguments, Type, TypePath, TypeReference};
use syn::punctuated::Punctuated;
use syn::visit_mut::{visit_type_mut, visit_type_path_mut, visit_type_reference_mut, VisitMut};

use crate::utils::path_ends_with;

pub(crate) struct LifetimeRemover;

impl VisitMut for LifetimeRemover {
Expand Down Expand Up @@ -38,8 +40,10 @@ pub(crate) struct SelfRenamer<'t> {

impl VisitMut for SelfRenamer<'_> {
fn visit_type_mut(&mut self, ty: &mut Type) {
if ty == &mut parse_quote!(Self) {
*ty = self.ty.clone();
if let Type::Path(typ) = ty {
if path_ends_with(&typ.path, "Self") {
*ty = self.ty.clone();
}
}
visit_type_mut(self, ty);
}
Expand Down

0 comments on commit eb6fbe3

Please sign in to comment.