diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-08-10 16:04:57 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-08-10 16:04:57 +0800 |
| commit | eebcdf6b163174ec1629d121264c0477652e3323 (patch) | |
| tree | f3b56721e4159fe4069a4524ce9d1a47c865019d /mingling_macros/src/func/register_help.rs | |
| parent | a9d5943939261e27e58bcf5cacbb618a0f63e999 (diff) | |
refactor(macros): clean up clippy lints and simplify code
Diffstat (limited to 'mingling_macros/src/func/register_help.rs')
| -rw-r--r-- | mingling_macros/src/func/register_help.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/mingling_macros/src/func/register_help.rs b/mingling_macros/src/func/register_help.rs index e715244..d1957a5 100644 --- a/mingling_macros/src/func/register_help.rs +++ b/mingling_macros/src/func/register_help.rs @@ -39,21 +39,28 @@ pub(crate) fn register_help(input: TokenStream) -> TokenStream { let entry_str = help_entry.to_string(); // Check if entry was already pre-inserted by `#[help]` attribute - let mut helps = get_global_set(&crate::HELP_REQUESTS).lock().unwrap(); - if helps.contains(&entry_str) { + let helps = get_global_set(&crate::HELP_REQUESTS); + let help_set = helps.lock().unwrap(); + if help_set.contains(&entry_str) { // Already registered by `#[help]`, no duplicate check needed return quote::quote! {}.into(); } // Check for duplicate variant (different struct, same type) let variant_name = entry_type.path.segments.last().unwrap().ident.to_string(); - if let Err(err) = - crate::check_duplicate_variant(&helps, &entry_str, &variant_name, "help", entry_type.span()) - { + let dup_check = crate::check_duplicate_variant( + &help_set, + &entry_str, + &variant_name, + "help", + entry_type.span(), + ); + if let Err(err) = dup_check { return err.into(); } - helps.insert(entry_str); + drop(help_set); + helps.lock().unwrap().insert(entry_str); quote::quote! {}.into() } |
