diff --git a/Cargo.toml b/Cargo.toml index 5d2d4f62..2eeb8437 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ include = [ "README.md", "CHANGELOG.md", "tests/**/*.rs", # debian packaging wants this + "examples/**/*.rs" ] [workspace] @@ -43,6 +44,9 @@ github = { repository = "JelteF/derive_more", workflow = "CI" } features = ["full"] rustdoc-args = ["--cfg", "docsrs"] +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } + [features] default = ["std"] diff --git a/impl/Cargo.toml b/impl/Cargo.toml index 41a45175..d18a2717 100644 --- a/impl/Cargo.toml +++ b/impl/Cargo.toml @@ -43,6 +43,9 @@ github = { repository = "JelteF/derive_more", workflow = "CI" } features = ["full"] rustdoc-args = ["--cfg", "docsrs"] +[lints.rust] +unexpected_cfgs = { level = "warn", check-cfg = ['cfg(ci)'] } + [features] default = [] diff --git a/impl/src/into.rs b/impl/src/into.rs index f426beca..b94811ea 100644 --- a/impl/src/into.rs +++ b/impl/src/into.rs @@ -217,6 +217,25 @@ impl From for ConversionsAttribute { } } +type Untyped = Either>; +impl From for FieldAttribute { + fn from(v: Untyped) -> Self { + match v { + Untyped::Left(skip) => Self { + skip: Some(skip), + convs: None, + }, + Untyped::Right(c) => Self { + skip: None, + convs: Some(match c { + Either::Left(_empty) => ConversionsAttribute::default(), + Either::Right(convs) => convs, + }), + }, + } + } +} + /// Representation of an [`Into`] derive macro field attribute. /// /// ```rust,ignore @@ -242,25 +261,6 @@ impl attr::ParseMultiple for FieldAttribute { attr: &syn::Attribute, parser: &P, ) -> syn::Result { - type Untyped = Either>; - impl From for FieldAttribute { - fn from(v: Untyped) -> Self { - match v { - Untyped::Left(skip) => Self { - skip: Some(skip), - convs: None, - }, - Untyped::Right(c) => Self { - skip: None, - convs: Some(match c { - Either::Left(_empty) => ConversionsAttribute::default(), - Either::Right(convs) => convs, - }), - }, - } - } - } - Untyped::parse_attr_with(attr, parser).map(Self::from) } diff --git a/impl/src/utils.rs b/impl/src/utils.rs index 73a4bbcf..5a6649cb 100644 --- a/impl/src/utils.rs +++ b/impl/src/utils.rs @@ -262,7 +262,6 @@ pub enum DeriveType { pub struct State<'input> { pub input: &'input DeriveInput, pub trait_name: &'static str, - pub trait_ident: Ident, pub method_ident: Ident, pub trait_path: TokenStream, pub trait_path_params: Vec, @@ -417,8 +416,7 @@ impl<'input> State<'input> { let meta_infos = meta_infos?; let first_match = meta_infos .iter() - .filter_map(|info| info.enabled.map(|_| info)) - .next(); + .find_map(|info| info.enabled.map(|_| info)); // Default to enabled true, except when first attribute has explicit // enabling. @@ -489,7 +487,6 @@ impl<'input> State<'input> { Ok(State { input, trait_name, - trait_ident, method_ident, trait_path, trait_path_params: vec![], @@ -546,7 +543,6 @@ impl<'input> State<'input> { trait_path, trait_path_params: vec![], trait_attr, - trait_ident, method_ident, // input, fields, @@ -579,7 +575,6 @@ impl<'input> State<'input> { field_type: data.field_types[0], member: data.members[0].clone(), info: data.infos[0].clone(), - field_ident: data.field_idents[0].clone(), trait_path: data.trait_path, trait_path_with_params: data.trait_path_with_params.clone(), casted_trait: data.casted_traits[0].clone(), @@ -652,17 +647,10 @@ impl<'input> State<'input> { panic!("can only derive({}) for enum", self.trait_name) } let variants = self.enabled_variants(); - let trait_path = &self.trait_path; - let (impl_generics, ty_generics, where_clause) = self.generics.split_for_impl(); MultiVariantData { - input_type: &self.input.ident, variants, variant_states: self.enabled_variant_states(), infos: self.enabled_infos(), - trait_path, - impl_generics, - ty_generics, - where_clause, } } @@ -744,7 +732,6 @@ pub struct SingleFieldData<'input, 'state> { pub input_type: &'input Ident, pub field: &'input Field, pub field_type: &'input Type, - pub field_ident: TokenStream, pub member: TokenStream, pub info: FullMetaInfo, pub trait_path: &'state TokenStream, @@ -779,14 +766,9 @@ pub struct MultiFieldData<'input, 'state> { } pub struct MultiVariantData<'input, 'state> { - pub input_type: &'input Ident, pub variants: Vec<&'input Variant>, pub variant_states: Vec<&'state State<'input>>, pub infos: Vec, - pub trait_path: &'state TokenStream, - pub impl_generics: ImplGenerics<'state>, - pub ty_generics: TypeGenerics<'state>, - pub where_clause: Option<&'state WhereClause>, } impl<'input, 'state> MultiFieldData<'input, 'state> {