don't double-derive ::bok::Repository and Debug

Signed-off-by: Luca Fulchir <luca.fulchir@runesauth.com>
This commit is contained in:
Luca Fulchir 2024-11-17 12:45:24 +01:00
parent 9a83bf0dfa
commit 96ac418e2f
Signed by: luca.fulchir
GPG Key ID: 8F6440603D13A78E
4 changed files with 39 additions and 14 deletions

View File

@ -13,7 +13,7 @@ categories = [ "config" ]
proc-macro = true
[dependencies]
syn = { version = "2.0", features = [ "full" ] }
syn = { version = "2.0", features = [ "full", "extra-traits" ] }
quote = { version = "1.0" }
proc-macro2 = "1.0"
macro_magic = { version = "0.5", features = [ "proc_support" ] }

View File

@ -102,17 +102,43 @@ pub(crate) fn repository(
};
let local_attrs = local.attrs.iter().filter(|&x| {
// don't export the same thing multiple times
if let ::syn::Meta::Path(p) = &x.meta {
match &x.meta {
::syn::Meta::Path(p) => {
// looking for:
// #[::macro_magic::export_tokens]
if p.segments.len() == 2
&& p.segments[0].ident == "macro_magic"
&& p.segments[1].ident == "export_tokens"
{
false
} else {
true
}
}
::syn::Meta::List(ml) => {
// looking for:
// #[derive(::bok::Repository, Debug)]
if ml.path.segments.len() > 0 && ml.path.is_ident("derive") {
use ::syn::{punctuated::Punctuated, *};
if let Ok(v) = ml.parse_args_with(
Punctuated::<::syn::Path, Token![,]>::parse_terminated,
) {
if v.len() == 2
&& v[0].segments.len() == 2
&& v[0].segments[0].ident.to_string() == "bok"
&& v[0].segments[1].ident.to_string()
== "Repository"
&& v[1].segments.len() == 1
&& v[1].segments[0].ident.to_string() == "Debug"
{
return false;
}
return true;
};
}
}
true
}
_ => true,
}
});
let generics = local.generics;
let ident = local.ident;
@ -134,7 +160,6 @@ pub(crate) fn repository(
.named
.iter()
.find(|&x| {
//
let Some(id) = &x.ident else {
return false;
};

View File

@ -17,5 +17,5 @@ macro_magic = { version = "0.5" }
prettyplease = "0.2"
proc-macro2 = "1.0"
quote = "1.0"
syn = { version = "2", features = [ "full", "parsing" ] }
syn = { version = "2", features = [ "full", "parsing", "extra-traits" ] }
sha3 = { version = "0.10" }

View File

@ -73,7 +73,7 @@ impl Pkgs2 {
}
}
/// This repository extends both Pkgs1 and Pkgs2
#[::bok::repository(Pkgs1)]
#[::bok::repository(Pkgs2)]
#[::bok::repository(Pkgs1)]
#[derive(::std::default::Default)]
pub struct Pkgs3 {}