Skip to content

Commit

Permalink
Update to syn 2
Browse files Browse the repository at this point in the history
  • Loading branch information
kaleidawave committed Mar 1, 2024
1 parent 08b0e9a commit 8a7d3cb
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 70 deletions.
50 changes: 27 additions & 23 deletions .github/workflows/crates.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
- 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 }}
72 changes: 55 additions & 17 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
35 changes: 19 additions & 16 deletions src/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand All @@ -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())
})
Expand Down Expand Up @@ -128,21 +128,24 @@ impl Default for ReferenceConfig {
impl Parse for ReferenceConfig {
fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> {
let flags = input
.parse_terminated::<_, Token![,]>(|input| {
if input.peek(Token![ref]) || input.peek(Token![&]) {
input.parse::<proc_macro2::TokenTree>().unwrap();
if input.peek(Token![mut]) {
input.parse::<Token![mut]>().unwrap();
Ok(ReferenceConfig::SharedMut)
.parse_terminated(
|input| {
if input.peek(Token![ref]) || input.peek(Token![&]) {
input.parse::<proc_macro2::TokenTree>().unwrap();
if input.peek(Token![mut]) {
input.parse::<Token![mut]>().unwrap();
Ok(ReferenceConfig::SharedMut)
} else {
Ok(ReferenceConfig::Shared)
}
} else if input.peek(Ident) && input.parse::<Ident>().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::<Ident>().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)
Expand Down Expand Up @@ -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()),
)),
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 8a7d3cb

Please sign in to comment.