From 8a7d3cb0d7b010b1bbc8afa24238ca7b6d2cd49d Mon Sep 17 00:00:00 2001 From: Ben Date: Fri, 1 Mar 2024 08:40:16 +0000 Subject: [PATCH] Update to syn 2 --- .github/workflows/crates.yml | 50 +++++++++++++------------ .github/workflows/rust.yml | 72 +++++++++++++++++++++++++++--------- Cargo.lock | 24 ++++++------ Cargo.toml | 6 ++- src/into.rs | 35 ++++++++++-------- src/lib.rs | 2 +- 6 files changed, 119 insertions(+), 70 deletions(-) diff --git a/.github/workflows/crates.yml b/.github/workflows/crates.yml index 843ceb4..b5f3a6b 100644 --- a/.github/workflows/crates.yml +++ b/.github/workflows/crates.yml @@ -8,30 +8,34 @@ on: required: false default: "patch" +concurrency: release-crate + jobs: publish: runs-on: ubuntu-latest + permissions: + contents: write steps: - - uses: actions/checkout@v2 - - name: Set git credentials - run: | - git config user.name github-actions - git config user.email github-actions@github.com - - name: Crates publish - uses: kaleidawave/crates-release-gh-action@v1 - id: release - with: - version: ${{ github.event.inputs.version }} - crates-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} - - name: Push updated Cargo.toml - run: | - git tag "v${{ steps.release.outputs.new-version }}" - git add . - git commit -m "Release: ${{ steps.release.outputs.new-version }}" - git push --tags origin main - - name: Discord - uses: rjstone/discord-webhook-notify@v1 - with: - severity: info - text: "Released version ${{ steps.release.outputs.new-version }}" - webhookUrl: ${{ secrets.DISCORD_WEBHOOK_ENDPOINT }} \ No newline at end of file + - uses: actions/checkout@v4 + - name: Set git credentials + run: | + git config user.name github-actions + git config user.email github-actions@github.com + - name: Crates publish + uses: kaleidawave/crates-release-gh-action@main + id: release + with: + version: ${{ github.event.inputs.version }} + crates-token: ${{ secrets.CARGO_REGISTRY_TOKEN }} + - name: Push updated Cargo.toml + run: | + git add . + git commit -m "Release: ${{ steps.release.outputs.new-versions-description }}" + git tag "release/${{ steps.release.outputs.new-version }}" + git push --tags origin main + - name: Discord + uses: dusmartijngames/discord-webhook-notify@master + with: + severity: info + text: "Released version ${{ steps.release.outputs.new-versions-description }}" + webhookUrl: ${{ secrets.DISCORD_WEBHOOK_ENDPOINT }} diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 58edffe..e349069 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -8,33 +8,71 @@ on: env: CARGO_TERM_COLOR: always + CACHE_PATHS: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ jobs: validity: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - uses: actions/cache@v2 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Check source is valid - run: cargo check + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ${{ env.CACHE_PATHS }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Check source is valid + run: cargo check --workspace + + formating: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Check formatting with rustfmt + run: cargo fmt --all --check + - uses: brndnmtthws/rust-action-cargo-binstall@v1 + with: + packages: taplo-cli + - name: Check TOML formatting with taplo + run: | + taplo fmt --check **/*/Cargo.toml tests: + needs: validity runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ${{ env.CACHE_PATHS }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Run all tests + run: cargo test --workspace --verbose --all-features + + clippy: needs: validity + runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Run tests - run: cargo test --verbose + - uses: actions/checkout@v4 + - uses: actions/cache@v4 + with: + path: ${{ env.CACHE_PATHS }} + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + - name: Lint code with clippy + run: cargo clippy - formating: + publish-ability: runs-on: ubuntu-latest + if: false steps: - - uses: actions/checkout@v2 - - name: Check formatting with rustfmt - run: cargo fmt --all -- --check \ No newline at end of file + - uses: actions/checkout@v4 + - name: Check that it will publish to crates + run: | + cargo metadata --offline --format-version 1 --no-deps | jq -r ".workspace_members[]" | while read -r _n _v pathInfo ; do + cd ${pathInfo:13:-1} + cargo publish --no-verify --dry-run + done + shell: bash diff --git a/Cargo.lock b/Cargo.lock index 2f43227..2fd7867 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "derive-enum-from-into" -version = "0.1.0" +version = "0.1.1" dependencies = [ "proc-macro2", "quote", @@ -13,35 +13,35 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.32" +version = "1.0.78" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba508cc11742c0dc5c1659771673afbab7a0efab23aa17e854cbab0837ed0b43" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" dependencies = [ - "unicode-xid", + "unicode-ident", ] [[package]] name = "quote" -version = "1.0.10" +version = "1.0.35" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" dependencies = [ "proc-macro2", ] [[package]] name = "syn" -version = "1.0.80" +version = "2.0.50" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d010a1623fbd906d51d650a9916aaefc05ffa0e4053ff7fe601167f3e715d194" +checksum = "74f1bdc9872430ce9b75da68329d1c1746faf50ffac5f19e02b71e37ff881ffb" dependencies = [ "proc-macro2", "quote", - "unicode-xid", + "unicode-ident", ] [[package]] -name = "unicode-xid" -version = "0.2.2" +name = "unicode-ident" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" diff --git a/Cargo.toml b/Cargo.toml index cba6d90..e527060 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,5 +16,9 @@ proc-macro = true [dependencies] proc-macro2 = "1.0" -syn = { version = "1.0", features = ["full", "extra-traits"] } +syn = { version = "2.0", features = ["full", "extra-traits"] } quote = "1.0" + +[workspace.lints.clippy] +all = "deny" +pedantic = "deny" diff --git a/src/into.rs b/src/into.rs index bf46505..bf1abf9 100644 --- a/src/into.rs +++ b/src/into.rs @@ -4,7 +4,7 @@ use proc_macro2::Span; use quote::quote; use syn::{ parse::Parse, parse_quote, token::Comma, Attribute, DataEnum, Error, GenericArgument, - GenericParam, Generics, Ident, Lifetime, LifetimeDef, Path, PathArguments, Token, Type, + GenericParam, Generics, Ident, Lifetime, LifetimeParam, Path, PathArguments, Token, Type, TypePath, TypeReference, }; @@ -28,7 +28,7 @@ pub(super) fn derive_enum_into( let references: ReferenceConfig = top_attributes .iter() .find_map(|attr| { - attr.path + attr.path() .is_ident("try_into_references") .then(|| attr.parse_args().unwrap()) }) @@ -128,21 +128,24 @@ impl Default for ReferenceConfig { impl Parse for ReferenceConfig { fn parse(input: syn::parse::ParseStream) -> syn::Result { let flags = input - .parse_terminated::<_, Token![,]>(|input| { - if input.peek(Token![ref]) || input.peek(Token![&]) { - input.parse::().unwrap(); - if input.peek(Token![mut]) { - input.parse::().unwrap(); - Ok(ReferenceConfig::SharedMut) + .parse_terminated( + |input| { + if input.peek(Token![ref]) || input.peek(Token![&]) { + input.parse::().unwrap(); + if input.peek(Token![mut]) { + input.parse::().unwrap(); + Ok(ReferenceConfig::SharedMut) + } else { + Ok(ReferenceConfig::Shared) + } + } else if input.peek(Ident) && input.parse::().unwrap() == "owned" { + Ok(ReferenceConfig::Owned) } else { - Ok(ReferenceConfig::Shared) + Err(Error::new(input.span(), "expected 'ref', '&' or 'owned'")) } - } else if input.peek(Ident) && input.parse::().unwrap() == "owned" { - Ok(ReferenceConfig::Owned) - } else { - Err(Error::new(input.span(), "expected 'ref', '&' or 'owned'")) - } - })? + }, + Token![,], + )? .into_iter() .map(|member| member as u8) .reduce(std::ops::BitOr::bitor) @@ -189,7 +192,7 @@ impl ReferenceDecorator { ReferenceDecorator::Owned => None, ReferenceDecorator::Shared(lifetime_name) | ReferenceDecorator::SharedMut(lifetime_name) => Some(GenericParam::Lifetime( - LifetimeDef::new(lifetime_name.clone()), + LifetimeParam::new(lifetime_name.clone()), )), } } diff --git a/src/lib.rs b/src/lib.rs index af2a76c..960e54f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -50,7 +50,7 @@ fn get_unnamed_single_non_ignored_variants<'a>( && !variant .attrs .iter() - .any(|attr| attr.path.is_ident(ignore_ident)) + .any(|attr| attr.path().is_ident(ignore_ident)) { Some(( variant.ident.clone(),