Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: 2
updates:
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
83 changes: 30 additions & 53 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
20 changes: 8 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@ pub fn derive_my_description(item: TokenStream) -> TokenStream {
let mut input = syn::parse::<syn::DeriveInput>(item).unwrap();

// Extract a description, modifying `input.attrs` to remove the matched attributes.
let MyDescription { name, version } = match deluxe::extract_attributes(&mut input) {
Ok(desc) => desc,
Err(e) => return e.into_compile_error().into()
let Ok(MyDescription { name, version }) = deluxe::extract_attributes(&mut input) else {
return e.into_compile_error().into()
};

let ident = &input.ident;
Expand Down Expand Up @@ -136,9 +135,8 @@ pub fn my_desc(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let MyDescription { name, version } = match deluxe::parse::<MyDescription>(attr) {
Ok(desc) => desc,
Err(e) => return e.into_compile_error().into()
let Ok(MyDescription { name, version }) = deluxe::parse(attr) else {
return e.into_compile_error().into()
};

let tokens = quote::quote! {
Expand Down Expand Up @@ -305,9 +303,8 @@ pub fn my_desc_mod(
attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let mut module = syn::parse::<syn::ItemMod>(item) {
Ok(module) => module,
Err(e) => return e.into_compile_error().into()
let mut Ok(module) = syn::parse::<syn::ItemMod>(item) else {
return e.into_compile_error().into()
};

let errors = deluxe::Errors::new();
Expand Down Expand Up @@ -533,9 +530,8 @@ pub fn derive_my_object(item: TokenStream) -> TokenStream {
let input = syn::parse::<syn::DeriveInput>(item).unwrap();

// `obj.container` now holds a reference to `input`
let obj: MyObject = match deluxe::parse_attributes(&input) {
Ok(obj) => obj,
Err(e) => return e.into_compile_error().into()
let Ok(obj: MyObject) = deluxe::parse_attributes(&input) else {
return e.into_compile_error().into()
};

let tokens = quote::quote! { /* ... generate some code here ... */ };
Expand Down
7 changes: 4 additions & 3 deletions core/parse_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions core/small_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::cmp::Ordering> {
Expand Down
8 changes: 4 additions & 4 deletions macros/parse_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,17 @@ pub fn impl_parse_attributes(input: syn::DeriveInput, errors: &Errors, mode: Mod
return Default::default();
}
};
let AttrImpl {
let Some(AttrImpl {
parse,
crate_path: crate_,
priv_path: priv_,
attributes,
container_field,
mut container_lifetime,
container_ty,
} = match attr {
Some(a) => a,
None => return Default::default(),
}) = attr
else {
return TokenStream::default();
};

let ident = &input.ident;
Expand Down
9 changes: 5 additions & 4 deletions macros/parse_meta_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,17 +335,18 @@ pub fn impl_parse_meta_item(input: syn::DeriveInput, errors: &Errors) -> TokenSt
return Default::default();
}
};
let MetaDef {

let Some(MetaDef {
parse,
inline,
flag,
default,
extra,
crate_path: crate_,
priv_path: priv_,
} = match meta {
Some(m) => m,
None => return Default::default(),
}) = meta
else {
return TokenStream::default();
};

let ident = &input.ident;
Expand Down
5 changes: 2 additions & 3 deletions macros/types/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,8 @@ impl<'e> ParseAttributes<'e, syn::DeriveInput> for Enum<'e> {
parse_helpers::parse_struct_attr_tokens(
parse_helpers::ref_tokens::<Self, _>(i),
|inputs, _| {
let enum_ = match &i.data {
syn::Data::Enum(e) => e,
_ => return Err(syn::Error::new_spanned(i, "wrong DeriveInput type")),
let syn::Data::Enum(enum_) = &i.data else {
return Err(syn::Error::new_spanned(i, "wrong DeriveInput type"));
};
let errors = crate::Errors::new();
let mut default = FieldStatus::<FieldDefault>::None;
Expand Down
29 changes: 17 additions & 12 deletions macros/types/field.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,13 @@ impl<'f> Field<'f> {
.enumerate()
.map(|(i, _)| quote::format_ident!("field{i}", span = Span::mixed_site()))
.collect::<Vec<_>>();
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 },
Expand All @@ -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! {};
Expand Down Expand Up @@ -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];
Expand Down
5 changes: 2 additions & 3 deletions macros/types/struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,8 @@ impl<'s> ParseAttributes<'s, syn::DeriveInput> for Struct<'s> {
parse_helpers::parse_struct_attr_tokens(
parse_helpers::ref_tokens::<Self, _>(i),
|inputs, _| {
let struct_ = match &i.data {
syn::Data::Struct(s) => s,
_ => return Err(syn::Error::new_spanned(i, "wrong DeriveInput type")),
let syn::Data::Struct(struct_) = &i.data else {
return Err(syn::Error::new_spanned(i, "wrong DeriveInput type"));
};
let errors = crate::Errors::new();
let mut transparent = FieldStatus::None;
Expand Down