Skip to content

Commit

Permalink
refactor(clippy): add stricter clippy lints
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewsonin committed May 18, 2024
1 parent deceb47 commit d74c00f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 19 deletions.
13 changes: 10 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gset"
version = "1.0.4"
version = "1.0.5"
authors = ["Andrew Sonin <[email protected]>"]
description = "A procedural macro for generating the most basic getters and setters on fields."
categories = ["development-tools::procedural-macro-helpers"]
Expand All @@ -24,5 +24,12 @@ proc-macro-error = "1"
proc-macro2 = "1"
syn = "1"

[dev-dependencies]
derive_more = "0.99"
[lints.rust]
rust_2018_idioms = { level = "warn", priority = 1 }
unreachable_pub = "warn"
missing_docs = "warn"
missing_debug_implementations = "warn"

[lints.clippy]
undocumented_unsafe_blocks = "warn"
pedantic = { level = "warn", priority = 1 }
23 changes: 12 additions & 11 deletions src/field_attribute_layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ use quote::quote;
use syn::{spanned::Spanned, Lit, Meta, MetaNameValue, Type, Visibility};

#[derive(Default)]
pub struct AttributeLayout {
pub fn_name_override: Option<Ident>,
pub visibility: Option<Visibility>,
pub kind: Option<AttributeKind>,
pub type_override: Option<Type>,
pub(crate) struct AttributeLayout {
fn_name_override: Option<Ident>,
visibility: Option<Visibility>,
kind: Option<AttributeKind>,
type_override: Option<Type>,
}

impl<T> From<T> for AttributeLayout
Expand All @@ -30,15 +30,15 @@ where
path
)
}
let kind: AttributeKind = path.parse().unwrap_or_else(|_| {
let kind: AttributeKind = path.parse().unwrap_or_else(|()| {
abort!(
meta.span(),
"Unknown getset kind attribute: `{}`. Should be one of: {}",
path,
AttributeKind::all_kinds()
)
});
current_layout.kind = kind.into()
current_layout.kind = kind.into();
}
Meta::List(list) => {
abort!(list.span(), "Multiple attributes are not supported")
Expand All @@ -54,19 +54,19 @@ where
current_layout.fn_name_override = syn::parse_str::<Ident>(&lit_str)
.map_err(|e| syn::Error::new(lit.span(), e))
.expect_or_abort("invalid ident")
.into()
.into();
}
"vis" => {
current_layout.visibility = syn::parse_str::<Visibility>(&lit_str)
.map_err(|e| syn::Error::new(lit.span(), e))
.expect_or_abort("invalid visibility found")
.into()
.into();
}
"ty" => {
current_layout.type_override = syn::parse_str::<Type>(&lit_str)
.map_err(|e| syn::Error::new(lit.span(), e))
.expect_or_abort("invalid ty found")
.into()
.into();
}
_ => abort!(
lit.span(),
Expand All @@ -81,7 +81,8 @@ where
}

impl AttributeLayout {
pub fn generate_fn_def(
#[allow(clippy::too_many_lines)]
pub(crate) fn generate_fn_def(
self,
field_ident_or_idx: &str,
field_type: &Type,
Expand Down
2 changes: 1 addition & 1 deletion src/field_attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ macro_rules! define_field_attributes

impl std::fmt::Display for $enum_name
{
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let msg: &str = self.into();
write!(f, "{msg}")
}
Expand Down
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ pub fn derive_getset(input: TokenStream) -> TokenStream {
} = &ast;
let (impl_generics, ty_generics, where_clause) = generics.split_for_impl();

let fields = match data {
Data::Struct(DataStruct { fields, .. }) => fields,
_ => abort_call_site!("#[derive(Getset)] is only supported for structs"),
let Data::Struct(DataStruct { fields, .. }) = data else {
abort_call_site!("#[derive(Getset)] is only supported for structs")
};

let mut impls = TokenStream2::new();
Expand All @@ -47,6 +46,7 @@ pub fn derive_getset(input: TokenStream) -> TokenStream {
continue;
}

#[allow(clippy::map_unwrap_or)]
let ident_or_index = field_ident
.as_ref()
.map(ToString::to_string)
Expand Down Expand Up @@ -77,7 +77,7 @@ pub fn derive_getset(input: TokenStream) -> TokenStream {
#fn_def
};

impls.extend(imp)
impls.extend(imp);
}
}

Expand Down

0 comments on commit d74c00f

Please sign in to comment.