diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..71607d0 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: +- package-ecosystem: github-actions + directory: "/" + schedule: + interval: daily diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d577df7..06628da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,78 +11,55 @@ env: jobs: build_and_test: - name: Deluxe + name: Build & Test + strategy: + matrix: + features: ["--all-features", "--no-default-features"] runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - run: cargo build -r --all-features --workspace - - run: cargo test -r --all-features --workspace - - build_and_test_no_default: - name: Deluxe No Default Features - runs-on: ubuntu-latest - timeout-minutes: 45 - steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - override: true - - run: cargo build -r --no-default-features --workspace - - run: cargo test -r --no-default-features --workspace + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly + - run: cargo build -r ${{ matrix.features }} --workspace + - run: cargo test -r ${{ matrix.features }} --workspace rustfmt: - name: Deluxe Rustfmt + name: Rustfmt runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly with: - profile: minimal - toolchain: stable - override: true components: rustfmt - - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check + - run: cargo fmt --all --check clippy: - name: Deluxe Clippy + name: Clippy runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@nightly with: - profile: minimal - toolchain: stable - override: true components: clippy - - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --workspace + - run: cargo clippy --workspace --all-targets docs: - name: Deluxe Docs + name: Docs runs-on: ubuntu-latest timeout-minutes: 45 steps: - - uses: actions/checkout@v3 - - uses: actions-rs/toolchain@v1 - with: - profile: minimal - toolchain: stable - override: true - components: rust-docs - - uses: actions-rs/cargo@v1 - with: - command: doc - args: --workspace + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@stable + - run: cargo doc --workspace --no-deps + + msrv: + runs-on: ubuntu-latest + env: + CARGO_NET_GIT_FETCH_WITH_CLI: true + steps: + - uses: actions/checkout@v4 + - uses: taiki-e/install-action@cargo-no-dev-deps + - uses: dtolnay/rust-toolchain@1.67.1 + - run: cargo no-dev-deps check diff --git a/Cargo.toml b/Cargo.toml index 6e842e3..5300989 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,6 +11,7 @@ readme = "README.md" keywords = ["macros", "derive", "attributes"] include = ["/src", "/tests", "/README.md", "/COPYING"] resolver = "2" +rust-version = "1.67.1" [features] default = ["full", "proc-macro"] diff --git a/core/parse_attributes.rs b/core/parse_attributes.rs index f34aa89..3e1d80d 100644 --- a/core/parse_attributes.rs +++ b/core/parse_attributes.rs @@ -121,88 +121,88 @@ impl_has_attributes!(syn::DeriveInput); impl HasAttributes for syn::Expr { fn attrs(&self) -> &[syn::Attribute] { match self { - syn::Expr::Array(expr) => &expr.attrs, - syn::Expr::Assign(expr) => &expr.attrs, - syn::Expr::Async(expr) => &expr.attrs, - syn::Expr::Await(expr) => &expr.attrs, - syn::Expr::Binary(expr) => &expr.attrs, - syn::Expr::Block(expr) => &expr.attrs, - syn::Expr::Break(expr) => &expr.attrs, - syn::Expr::Call(expr) => &expr.attrs, - syn::Expr::Cast(expr) => &expr.attrs, - syn::Expr::Closure(expr) => &expr.attrs, - syn::Expr::Const(expr) => &expr.attrs, - syn::Expr::Continue(expr) => &expr.attrs, - syn::Expr::Field(expr) => &expr.attrs, - syn::Expr::ForLoop(expr) => &expr.attrs, - syn::Expr::Group(expr) => &expr.attrs, - syn::Expr::If(expr) => &expr.attrs, - syn::Expr::Index(expr) => &expr.attrs, - syn::Expr::Infer(expr) => &expr.attrs, - syn::Expr::Let(expr) => &expr.attrs, - syn::Expr::Lit(expr) => &expr.attrs, - syn::Expr::Loop(expr) => &expr.attrs, - syn::Expr::Macro(expr) => &expr.attrs, - syn::Expr::Match(expr) => &expr.attrs, - syn::Expr::MethodCall(expr) => &expr.attrs, - syn::Expr::Paren(expr) => &expr.attrs, - syn::Expr::Path(expr) => &expr.attrs, - syn::Expr::Range(expr) => &expr.attrs, - syn::Expr::Reference(expr) => &expr.attrs, - syn::Expr::Repeat(expr) => &expr.attrs, - syn::Expr::Return(expr) => &expr.attrs, - syn::Expr::Struct(expr) => &expr.attrs, - syn::Expr::Try(expr) => &expr.attrs, - syn::Expr::TryBlock(expr) => &expr.attrs, - syn::Expr::Tuple(expr) => &expr.attrs, - syn::Expr::Unary(expr) => &expr.attrs, - syn::Expr::Unsafe(expr) => &expr.attrs, - syn::Expr::While(expr) => &expr.attrs, - syn::Expr::Yield(expr) => &expr.attrs, + Self::Array(expr) => &expr.attrs, + Self::Assign(expr) => &expr.attrs, + Self::Async(expr) => &expr.attrs, + Self::Await(expr) => &expr.attrs, + Self::Binary(expr) => &expr.attrs, + Self::Block(expr) => &expr.attrs, + Self::Break(expr) => &expr.attrs, + Self::Call(expr) => &expr.attrs, + Self::Cast(expr) => &expr.attrs, + Self::Closure(expr) => &expr.attrs, + Self::Const(expr) => &expr.attrs, + Self::Continue(expr) => &expr.attrs, + Self::Field(expr) => &expr.attrs, + Self::ForLoop(expr) => &expr.attrs, + Self::Group(expr) => &expr.attrs, + Self::If(expr) => &expr.attrs, + Self::Index(expr) => &expr.attrs, + Self::Infer(expr) => &expr.attrs, + Self::Let(expr) => &expr.attrs, + Self::Lit(expr) => &expr.attrs, + Self::Loop(expr) => &expr.attrs, + Self::Macro(expr) => &expr.attrs, + Self::Match(expr) => &expr.attrs, + Self::MethodCall(expr) => &expr.attrs, + Self::Paren(expr) => &expr.attrs, + Self::Path(expr) => &expr.attrs, + Self::Range(expr) => &expr.attrs, + Self::Reference(expr) => &expr.attrs, + Self::Repeat(expr) => &expr.attrs, + Self::Return(expr) => &expr.attrs, + Self::Struct(expr) => &expr.attrs, + Self::Try(expr) => &expr.attrs, + Self::TryBlock(expr) => &expr.attrs, + Self::Tuple(expr) => &expr.attrs, + Self::Unary(expr) => &expr.attrs, + Self::Unsafe(expr) => &expr.attrs, + Self::While(expr) => &expr.attrs, + Self::Yield(expr) => &expr.attrs, _ => &[], } } fn attrs_mut(&mut self) -> Result<&mut Vec> { match self { - syn::Expr::Array(expr) => Ok(&mut expr.attrs), - syn::Expr::Assign(expr) => Ok(&mut expr.attrs), - syn::Expr::Async(expr) => Ok(&mut expr.attrs), - syn::Expr::Await(expr) => Ok(&mut expr.attrs), - syn::Expr::Binary(expr) => Ok(&mut expr.attrs), - syn::Expr::Block(expr) => Ok(&mut expr.attrs), - syn::Expr::Break(expr) => Ok(&mut expr.attrs), - syn::Expr::Call(expr) => Ok(&mut expr.attrs), - syn::Expr::Cast(expr) => Ok(&mut expr.attrs), - syn::Expr::Closure(expr) => Ok(&mut expr.attrs), - syn::Expr::Const(expr) => Ok(&mut expr.attrs), - syn::Expr::Continue(expr) => Ok(&mut expr.attrs), - syn::Expr::Field(expr) => Ok(&mut expr.attrs), - syn::Expr::ForLoop(expr) => Ok(&mut expr.attrs), - syn::Expr::Group(expr) => Ok(&mut expr.attrs), - syn::Expr::If(expr) => Ok(&mut expr.attrs), - syn::Expr::Index(expr) => Ok(&mut expr.attrs), - syn::Expr::Let(expr) => Ok(&mut expr.attrs), - syn::Expr::Lit(expr) => Ok(&mut expr.attrs), - syn::Expr::Loop(expr) => Ok(&mut expr.attrs), - syn::Expr::Macro(expr) => Ok(&mut expr.attrs), - syn::Expr::Match(expr) => Ok(&mut expr.attrs), - syn::Expr::MethodCall(expr) => Ok(&mut expr.attrs), - syn::Expr::Paren(expr) => Ok(&mut expr.attrs), - syn::Expr::Path(expr) => Ok(&mut expr.attrs), - syn::Expr::Range(expr) => Ok(&mut expr.attrs), - syn::Expr::Reference(expr) => Ok(&mut expr.attrs), - syn::Expr::Repeat(expr) => Ok(&mut expr.attrs), - syn::Expr::Return(expr) => Ok(&mut expr.attrs), - syn::Expr::Struct(expr) => Ok(&mut expr.attrs), - syn::Expr::Try(expr) => Ok(&mut expr.attrs), - syn::Expr::TryBlock(expr) => Ok(&mut expr.attrs), - syn::Expr::Tuple(expr) => Ok(&mut expr.attrs), - syn::Expr::Unary(expr) => Ok(&mut expr.attrs), - syn::Expr::Unsafe(expr) => Ok(&mut expr.attrs), - syn::Expr::While(expr) => Ok(&mut expr.attrs), - syn::Expr::Yield(expr) => Ok(&mut expr.attrs), - syn::Expr::Verbatim(_) => Err(syn::Error::new_spanned( + Self::Array(expr) => Ok(&mut expr.attrs), + Self::Assign(expr) => Ok(&mut expr.attrs), + Self::Async(expr) => Ok(&mut expr.attrs), + Self::Await(expr) => Ok(&mut expr.attrs), + Self::Binary(expr) => Ok(&mut expr.attrs), + Self::Block(expr) => Ok(&mut expr.attrs), + Self::Break(expr) => Ok(&mut expr.attrs), + Self::Call(expr) => Ok(&mut expr.attrs), + Self::Cast(expr) => Ok(&mut expr.attrs), + Self::Closure(expr) => Ok(&mut expr.attrs), + Self::Const(expr) => Ok(&mut expr.attrs), + Self::Continue(expr) => Ok(&mut expr.attrs), + Self::Field(expr) => Ok(&mut expr.attrs), + Self::ForLoop(expr) => Ok(&mut expr.attrs), + Self::Group(expr) => Ok(&mut expr.attrs), + Self::If(expr) => Ok(&mut expr.attrs), + Self::Index(expr) => Ok(&mut expr.attrs), + Self::Let(expr) => Ok(&mut expr.attrs), + Self::Lit(expr) => Ok(&mut expr.attrs), + Self::Loop(expr) => Ok(&mut expr.attrs), + Self::Macro(expr) => Ok(&mut expr.attrs), + Self::Match(expr) => Ok(&mut expr.attrs), + Self::MethodCall(expr) => Ok(&mut expr.attrs), + Self::Paren(expr) => Ok(&mut expr.attrs), + Self::Path(expr) => Ok(&mut expr.attrs), + Self::Range(expr) => Ok(&mut expr.attrs), + Self::Reference(expr) => Ok(&mut expr.attrs), + Self::Repeat(expr) => Ok(&mut expr.attrs), + Self::Return(expr) => Ok(&mut expr.attrs), + Self::Struct(expr) => Ok(&mut expr.attrs), + Self::Try(expr) => Ok(&mut expr.attrs), + Self::TryBlock(expr) => Ok(&mut expr.attrs), + Self::Tuple(expr) => Ok(&mut expr.attrs), + Self::Unary(expr) => Ok(&mut expr.attrs), + Self::Unsafe(expr) => Ok(&mut expr.attrs), + Self::While(expr) => Ok(&mut expr.attrs), + Self::Yield(expr) => Ok(&mut expr.attrs), + Self::Verbatim(_) => Err(syn::Error::new_spanned( self, "`HasAttributes::attrs_mut` not supported with `syn::Expr::Verbatim`", )), @@ -262,20 +262,20 @@ impl_has_attributes!(syn::File, #full); impl HasAttributes for syn::ForeignItem { fn attrs(&self) -> &[syn::Attribute] { match self { - syn::ForeignItem::Fn(item) => &item.attrs, - syn::ForeignItem::Static(item) => &item.attrs, - syn::ForeignItem::Type(item) => &item.attrs, - syn::ForeignItem::Macro(item) => &item.attrs, + Self::Fn(item) => &item.attrs, + Self::Static(item) => &item.attrs, + Self::Type(item) => &item.attrs, + Self::Macro(item) => &item.attrs, _ => &[], } } fn attrs_mut(&mut self) -> Result<&mut Vec> { match self { - syn::ForeignItem::Fn(item) => Ok(&mut item.attrs), - syn::ForeignItem::Static(item) => Ok(&mut item.attrs), - syn::ForeignItem::Type(item) => Ok(&mut item.attrs), - syn::ForeignItem::Macro(item) => Ok(&mut item.attrs), - syn::ForeignItem::Verbatim(_) => Err(syn::Error::new_spanned( + Self::Fn(item) => Ok(&mut item.attrs), + Self::Static(item) => Ok(&mut item.attrs), + Self::Type(item) => Ok(&mut item.attrs), + Self::Macro(item) => Ok(&mut item.attrs), + Self::Verbatim(_) => Err(syn::Error::new_spanned( self, "`HasAttributes::attrs_mut` not supported with `syn::ForeignItem::Verbatim`", )), @@ -297,20 +297,20 @@ impl_has_attributes!(syn::ForeignItemType, #full); impl HasAttributes for syn::ImplItem { fn attrs(&self) -> &[syn::Attribute] { match self { - syn::ImplItem::Const(item) => &item.attrs, - syn::ImplItem::Fn(item) => &item.attrs, - syn::ImplItem::Type(item) => &item.attrs, - syn::ImplItem::Macro(item) => &item.attrs, + Self::Const(item) => &item.attrs, + Self::Fn(item) => &item.attrs, + Self::Type(item) => &item.attrs, + Self::Macro(item) => &item.attrs, _ => &[], } } fn attrs_mut(&mut self) -> Result<&mut Vec> { match self { - syn::ImplItem::Const(item) => Ok(&mut item.attrs), - syn::ImplItem::Fn(item) => Ok(&mut item.attrs), - syn::ImplItem::Type(item) => Ok(&mut item.attrs), - syn::ImplItem::Macro(item) => Ok(&mut item.attrs), - syn::ImplItem::Verbatim(_) => Err(syn::Error::new_spanned( + Self::Const(item) => Ok(&mut item.attrs), + Self::Fn(item) => Ok(&mut item.attrs), + Self::Type(item) => Ok(&mut item.attrs), + Self::Macro(item) => Ok(&mut item.attrs), + Self::Verbatim(_) => Err(syn::Error::new_spanned( self, "`HasAttributes::attrs_mut` not supported with `syn::ImplItem::Verbatim`", )), @@ -332,42 +332,42 @@ impl_has_attributes!(syn::ImplItemType, #full); impl HasAttributes for syn::Item { fn attrs(&self) -> &[syn::Attribute] { match self { - syn::Item::Const(expr) => &expr.attrs, - syn::Item::Enum(expr) => &expr.attrs, - syn::Item::ExternCrate(expr) => &expr.attrs, - syn::Item::Fn(expr) => &expr.attrs, - syn::Item::ForeignMod(expr) => &expr.attrs, - syn::Item::Impl(expr) => &expr.attrs, - syn::Item::Macro(expr) => &expr.attrs, - syn::Item::Mod(expr) => &expr.attrs, - syn::Item::Static(expr) => &expr.attrs, - syn::Item::Struct(expr) => &expr.attrs, - syn::Item::Trait(expr) => &expr.attrs, - syn::Item::TraitAlias(expr) => &expr.attrs, - syn::Item::Type(expr) => &expr.attrs, - syn::Item::Union(expr) => &expr.attrs, - syn::Item::Use(expr) => &expr.attrs, + Self::Const(expr) => &expr.attrs, + Self::Enum(expr) => &expr.attrs, + Self::ExternCrate(expr) => &expr.attrs, + Self::Fn(expr) => &expr.attrs, + Self::ForeignMod(expr) => &expr.attrs, + Self::Impl(expr) => &expr.attrs, + Self::Macro(expr) => &expr.attrs, + Self::Mod(expr) => &expr.attrs, + Self::Static(expr) => &expr.attrs, + Self::Struct(expr) => &expr.attrs, + Self::Trait(expr) => &expr.attrs, + Self::TraitAlias(expr) => &expr.attrs, + Self::Type(expr) => &expr.attrs, + Self::Union(expr) => &expr.attrs, + Self::Use(expr) => &expr.attrs, _ => &[], } } fn attrs_mut(&mut self) -> Result<&mut Vec> { match self { - syn::Item::Const(expr) => Ok(&mut expr.attrs), - syn::Item::Enum(expr) => Ok(&mut expr.attrs), - syn::Item::ExternCrate(expr) => Ok(&mut expr.attrs), - syn::Item::Fn(expr) => Ok(&mut expr.attrs), - syn::Item::ForeignMod(expr) => Ok(&mut expr.attrs), - syn::Item::Impl(expr) => Ok(&mut expr.attrs), - syn::Item::Macro(expr) => Ok(&mut expr.attrs), - syn::Item::Mod(expr) => Ok(&mut expr.attrs), - syn::Item::Static(expr) => Ok(&mut expr.attrs), - syn::Item::Struct(expr) => Ok(&mut expr.attrs), - syn::Item::Trait(expr) => Ok(&mut expr.attrs), - syn::Item::TraitAlias(expr) => Ok(&mut expr.attrs), - syn::Item::Type(expr) => Ok(&mut expr.attrs), - syn::Item::Union(expr) => Ok(&mut expr.attrs), - syn::Item::Use(expr) => Ok(&mut expr.attrs), - syn::Item::Verbatim(_) => Err(syn::Error::new_spanned( + Self::Const(expr) => Ok(&mut expr.attrs), + Self::Enum(expr) => Ok(&mut expr.attrs), + Self::ExternCrate(expr) => Ok(&mut expr.attrs), + Self::Fn(expr) => Ok(&mut expr.attrs), + Self::ForeignMod(expr) => Ok(&mut expr.attrs), + Self::Impl(expr) => Ok(&mut expr.attrs), + Self::Macro(expr) => Ok(&mut expr.attrs), + Self::Mod(expr) => Ok(&mut expr.attrs), + Self::Static(expr) => Ok(&mut expr.attrs), + Self::Struct(expr) => Ok(&mut expr.attrs), + Self::Trait(expr) => Ok(&mut expr.attrs), + Self::TraitAlias(expr) => Ok(&mut expr.attrs), + Self::Type(expr) => Ok(&mut expr.attrs), + Self::Union(expr) => Ok(&mut expr.attrs), + Self::Use(expr) => Ok(&mut expr.attrs), + Self::Verbatim(_) => Err(syn::Error::new_spanned( self, "`HasAttributes::attrs_mut` not supported with `syn::Item::Verbatim`", )), @@ -402,44 +402,44 @@ impl_has_attributes!(syn::Local, #full); impl HasAttributes for syn::Pat { fn attrs(&self) -> &[syn::Attribute] { match self { - syn::Pat::Const(expr) => &expr.attrs, - syn::Pat::Ident(expr) => &expr.attrs, - syn::Pat::Lit(expr) => &expr.attrs, - syn::Pat::Macro(expr) => &expr.attrs, - syn::Pat::Or(expr) => &expr.attrs, - syn::Pat::Paren(expr) => &expr.attrs, - syn::Pat::Path(expr) => &expr.attrs, - syn::Pat::Range(expr) => &expr.attrs, - syn::Pat::Reference(expr) => &expr.attrs, - syn::Pat::Rest(expr) => &expr.attrs, - syn::Pat::Slice(expr) => &expr.attrs, - syn::Pat::Struct(expr) => &expr.attrs, - syn::Pat::Tuple(expr) => &expr.attrs, - syn::Pat::TupleStruct(expr) => &expr.attrs, - syn::Pat::Type(expr) => &expr.attrs, - syn::Pat::Wild(expr) => &expr.attrs, + Self::Const(expr) => &expr.attrs, + Self::Ident(expr) => &expr.attrs, + Self::Lit(expr) => &expr.attrs, + Self::Macro(expr) => &expr.attrs, + Self::Or(expr) => &expr.attrs, + Self::Paren(expr) => &expr.attrs, + Self::Path(expr) => &expr.attrs, + Self::Range(expr) => &expr.attrs, + Self::Reference(expr) => &expr.attrs, + Self::Rest(expr) => &expr.attrs, + Self::Slice(expr) => &expr.attrs, + Self::Struct(expr) => &expr.attrs, + Self::Tuple(expr) => &expr.attrs, + Self::TupleStruct(expr) => &expr.attrs, + Self::Type(expr) => &expr.attrs, + Self::Wild(expr) => &expr.attrs, _ => &[], } } fn attrs_mut(&mut self) -> Result<&mut Vec> { match self { - syn::Pat::Const(expr) => Ok(&mut expr.attrs), - syn::Pat::Ident(expr) => Ok(&mut expr.attrs), - syn::Pat::Lit(expr) => Ok(&mut expr.attrs), - syn::Pat::Macro(expr) => Ok(&mut expr.attrs), - syn::Pat::Or(expr) => Ok(&mut expr.attrs), - syn::Pat::Paren(expr) => Ok(&mut expr.attrs), - syn::Pat::Path(expr) => Ok(&mut expr.attrs), - syn::Pat::Range(expr) => Ok(&mut expr.attrs), - syn::Pat::Reference(expr) => Ok(&mut expr.attrs), - syn::Pat::Rest(expr) => Ok(&mut expr.attrs), - syn::Pat::Slice(expr) => Ok(&mut expr.attrs), - syn::Pat::Struct(expr) => Ok(&mut expr.attrs), - syn::Pat::Tuple(expr) => Ok(&mut expr.attrs), - syn::Pat::TupleStruct(expr) => Ok(&mut expr.attrs), - syn::Pat::Type(expr) => Ok(&mut expr.attrs), - syn::Pat::Wild(expr) => Ok(&mut expr.attrs), - syn::Pat::Verbatim(_) => Err(syn::Error::new_spanned( + Self::Const(expr) => Ok(&mut expr.attrs), + Self::Ident(expr) => Ok(&mut expr.attrs), + Self::Lit(expr) => Ok(&mut expr.attrs), + Self::Macro(expr) => Ok(&mut expr.attrs), + Self::Or(expr) => Ok(&mut expr.attrs), + Self::Paren(expr) => Ok(&mut expr.attrs), + Self::Path(expr) => Ok(&mut expr.attrs), + Self::Range(expr) => Ok(&mut expr.attrs), + Self::Reference(expr) => Ok(&mut expr.attrs), + Self::Rest(expr) => Ok(&mut expr.attrs), + Self::Slice(expr) => Ok(&mut expr.attrs), + Self::Struct(expr) => Ok(&mut expr.attrs), + Self::Tuple(expr) => Ok(&mut expr.attrs), + Self::TupleStruct(expr) => Ok(&mut expr.attrs), + Self::Type(expr) => Ok(&mut expr.attrs), + Self::Wild(expr) => Ok(&mut expr.attrs), + Self::Verbatim(_) => Err(syn::Error::new_spanned( self, "`HasAttributes::attrs_mut` not supported with `syn::Pat::Verbatim`", )), @@ -469,20 +469,20 @@ impl_has_attributes!(syn::Receiver, #full); impl HasAttributes for syn::TraitItem { fn attrs(&self) -> &[syn::Attribute] { match self { - syn::TraitItem::Const(item) => &item.attrs, - syn::TraitItem::Fn(item) => &item.attrs, - syn::TraitItem::Type(item) => &item.attrs, - syn::TraitItem::Macro(item) => &item.attrs, + Self::Const(item) => &item.attrs, + Self::Fn(item) => &item.attrs, + Self::Type(item) => &item.attrs, + Self::Macro(item) => &item.attrs, _ => &[], } } fn attrs_mut(&mut self) -> Result<&mut Vec> { match self { - syn::TraitItem::Const(item) => Ok(&mut item.attrs), - syn::TraitItem::Fn(item) => Ok(&mut item.attrs), - syn::TraitItem::Type(item) => Ok(&mut item.attrs), - syn::TraitItem::Macro(item) => Ok(&mut item.attrs), - syn::TraitItem::Verbatim(_) => Err(syn::Error::new_spanned( + Self::Const(item) => Ok(&mut item.attrs), + Self::Fn(item) => Ok(&mut item.attrs), + Self::Type(item) => Ok(&mut item.attrs), + Self::Macro(item) => Ok(&mut item.attrs), + Self::Verbatim(_) => Err(syn::Error::new_spanned( self, "`HasAttributes::attrs_mut` not supported with `syn::TraitItem::Verbatim`", )), diff --git a/core/parse_helpers.rs b/core/parse_helpers.rs index 18748bd..1a3d1f4 100644 --- a/core/parse_helpers.rs +++ b/core/parse_helpers.rs @@ -84,20 +84,20 @@ impl FieldStatus { } /// Returns the status if it contains a value, or if it is `None` then returns `b`. #[inline] - pub fn or(self, b: FieldStatus) -> FieldStatus { + pub fn or(self, b: Self) -> Self { match self { - Self::Some(x) => FieldStatus::Some(x), - Self::ParseError => FieldStatus::ParseError, + Self::Some(x) => Self::Some(x), + Self::ParseError => Self::ParseError, Self::None => b, } } /// Returns the status if it contains a value, or if it is `None` then calls `f` and returns /// the result. #[inline] - pub fn or_else FieldStatus>(self, f: F) -> FieldStatus { + pub fn or_else Self>(self, f: F) -> Self { match self { - Self::Some(x) => FieldStatus::Some(x), - Self::ParseError => FieldStatus::ParseError, + Self::Some(x) => Self::Some(x), + Self::ParseError => Self::ParseError, Self::None => f(), } } @@ -168,12 +168,12 @@ impl FieldStatus { match errors.push_result(func(input, name, span)) { Some(v) => { if self.is_none() { - *self = FieldStatus::Some(v) + *self = Self::Some(v) } } None => { if self.is_none() { - *self = FieldStatus::ParseError; + *self = Self::ParseError; } skip_meta_item(input); } @@ -194,9 +194,9 @@ impl FieldStatus { F: FnOnce(ParseStream, ParseMode) -> Result, { match errors.push_result(func(input, ParseMode::Unnamed)) { - Some(v) => *self = FieldStatus::Some(v), + Some(v) => *self = Self::Some(v), None => { - *self = FieldStatus::ParseError; + *self = Self::ParseError; skip_meta_item(input); } } @@ -939,8 +939,10 @@ where P: crate::ParseAttributes<'t, T>, T: crate::HasAttributes, { - T::attrs(input).iter().filter_map(|a| { - P::path_matches(a.path()).then(|| { + T::attrs(input) + .iter() + .filter(|&a| P::path_matches(a.path())) + .map(|a| { let value = match &a.meta { syn::Meta::Path(_) => Default::default(), syn::Meta::List(list) => proc_macro2::TokenTree::Group(proc_macro2::Group::new( @@ -956,7 +958,6 @@ where }; (value, key_to_string(a.path()), a.path().span()) }) - }) } /// Returns an iterator of [`TokenStream`](proc_macro2::TokenStream)s and the corresponding path diff --git a/core/parse_meta.rs b/core/parse_meta.rs index a4c2dae..96a4b6c 100644 --- a/core/parse_meta.rs +++ b/core/parse_meta.rs @@ -1070,7 +1070,7 @@ impl ParseMetaItem for proc_macro2::Group { [Parenthesis, Brace, Bracket, None] } { if let Some((group, _, cursor)) = cursor.group(delim) { - return Ok((proc_macro2::Group::new(delim, group.token_stream()), cursor)); + return Ok((Self::new(delim, group.token_stream()), cursor)); } } Err(crate::Error::new( @@ -1224,7 +1224,7 @@ impl ParseMetaFlatUnnamed for Punct _mode: ParseMode, _index: usize, ) -> Result { - let mut p = Punctuated::new(); + let mut p = Self::new(); let errors = Errors::new(); for input in inputs { let input = input.borrow(); @@ -1384,7 +1384,7 @@ impl_parse_meta_paren_item_syn!(syn::MetaNameValue); impl ParseMetaItem for syn::Pat { #[inline] fn parse_meta_item(input: ParseStream, _mode: ParseMode) -> Result { - syn::Pat::parse_single(input) + Self::parse_single(input) } } #[cfg(feature = "full")] diff --git a/core/small_string.rs b/core/small_string.rs index 1ecd2b8..7e7bfb9 100644 --- a/core/small_string.rs +++ b/core/small_string.rs @@ -103,6 +103,7 @@ impl<'a> Ord for SmallString<'a> { } } +#[allow(clippy::non_canonical_partial_ord_impl)] impl<'a> PartialOrd for SmallString<'a> { #[inline] fn partial_cmp(&self, other: &Self) -> Option { diff --git a/core/util.rs b/core/util.rs index 0a4be77..d052ed5 100644 --- a/core/util.rs +++ b/core/util.rs @@ -262,7 +262,7 @@ impl SpannedValue { } /// Unwraps a `SpannedValue` into a `T`. Note this is an associated function, not a method. #[inline] - pub fn into_inner(value: SpannedValue) -> T { + pub fn into_inner(value: Self) -> T { value.value } } diff --git a/macros/types/field.rs b/macros/types/field.rs index a02e729..da721e2 100644 --- a/macros/types/field.rs +++ b/macros/types/field.rs @@ -18,7 +18,7 @@ pub enum FieldDefault { impl FieldDefault { pub fn to_expr(&self, ty: Option<&syn::Type>, priv_: &syn::Path) -> Cow { match self { - FieldDefault::Default(span) => { + Self::Default(span) => { let ty = if let Some(ty) = ty { quote_spanned! { ty.span() => #ty } } else { @@ -28,7 +28,7 @@ impl FieldDefault { <#ty as #priv_::Default>::default() }) } - FieldDefault::Expr(expr) => Cow::Borrowed(expr), + Self::Expr(expr) => Cow::Borrowed(expr), } } } @@ -507,9 +507,13 @@ impl<'f> Field<'f> { .enumerate() .map(|(i, _)| quote::format_ident!("field{i}", span = Span::mixed_site())) .collect::>(); - let container_def = fields.iter().enumerate().filter_map(|(i, f)| { - (f.is_container() && *mode != TokenMode::ParseMetaItem).then(|| { - let name = names[i].clone(); + let container_def = fields + .iter() + .zip(&names) + .filter_map(|(f, name)| { + (f.is_container() && *mode != TokenMode::ParseMetaItem).then_some(name) + }) + .map(|name| { let func = match mode { TokenMode::ParseAttributes => quote! { container_from }, TokenMode::ExtractAttributes => quote! { container_from_mut }, @@ -518,8 +522,7 @@ impl<'f> Field<'f> { quote_mixed! { #name = #priv_::FieldStatus::Some(#crate_::ContainerFrom::#func(obj)); } - }) - }); + }); let field_errors = { let mut cur_index = 0usize; let mut extra_counts = quote! {}; @@ -685,14 +688,16 @@ impl<'f> Field<'f> { #(#transforms)* } }); - let field_unwraps = fields.iter().enumerate().filter_map(|(i, _)| { - (!matches!(target, ParseTarget::Var(_))).then(|| { - let name = &names[i]; - quote_mixed! { - let #name = #name.unwrap_or_else(|| #priv_::unreachable!()); - } + let field_unwraps = (!matches!(target, ParseTarget::Var(_))) + .then(|| { + names.iter().take(fields.len()).map(|name| { + quote_mixed! { + let #name = #name.unwrap_or_else(|| #priv_::unreachable!()); + } + }) }) - }); + .into_iter() + .flatten(); let option_inits = fields.iter().enumerate().map(|(i, f)| { let name = &names[i];