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 proc-macro = true
[dependencies] [dependencies]
syn = { version = "2.0", features = [ "full" ] } syn = { version = "2.0", features = [ "full", "extra-traits" ] }
quote = { version = "1.0" } quote = { version = "1.0" }
proc-macro2 = "1.0" proc-macro2 = "1.0"
macro_magic = { version = "0.5", features = [ "proc_support" ] } 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| { let local_attrs = local.attrs.iter().filter(|&x| {
// don't export the same thing multiple times match &x.meta {
if let ::syn::Meta::Path(p) = &x.meta { ::syn::Meta::Path(p) => {
if p.segments.len() == 2 // looking for:
&& p.segments[0].ident == "macro_magic" // #[::macro_magic::export_tokens]
&& p.segments[1].ident == "export_tokens" if p.segments.len() == 2
{ && p.segments[0].ident == "macro_magic"
return false; && p.segments[1].ident == "export_tokens"
{
false
} else {
true
}
} }
return true; ::syn::Meta::List(ml) => {
}; // looking for:
true // #[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;
}
}
}
true
}
_ => true,
}
}); });
let generics = local.generics; let generics = local.generics;
let ident = local.ident; let ident = local.ident;
@ -134,7 +160,6 @@ pub(crate) fn repository(
.named .named
.iter() .iter()
.find(|&x| { .find(|&x| {
//
let Some(id) = &x.ident else { let Some(id) = &x.ident else {
return false; return false;
}; };

View File

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

View File

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