diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-26 20:56:24 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-26 20:56:24 +0800 |
| commit | 5714eba48ee9031d61858425583c219b881f2d13 (patch) | |
| tree | 714a2f82d7652ab14433a9ea4c129c30f6d04597 /mingling_macros/src/attr | |
| parent | 2cb8893711b73ccde946ca83e01dc315a9294c23 (diff) | |
feat(macros): split monolith into one-macro-per-file modules
Diffstat (limited to 'mingling_macros/src/attr')
| -rw-r--r-- | mingling_macros/src/attr/help.rs | 57 | ||||
| -rw-r--r-- | mingling_macros/src/attr/mlint.rs | 7 |
2 files changed, 9 insertions, 55 deletions
diff --git a/mingling_macros/src/attr/help.rs b/mingling_macros/src/attr/help.rs index aa7bc88..b4ad989 100644 --- a/mingling_macros/src/attr/help.rs +++ b/mingling_macros/src/attr/help.rs @@ -1,5 +1,5 @@ use proc_macro::TokenStream; -use quote::{ToTokens, quote}; +use quote::quote; use syn::spanned::Spanned; use syn::{Ident, ItemFn, Pat, ReturnType, Signature, TypePath, parse_macro_input}; @@ -154,7 +154,7 @@ pub(crate) fn help_attr(item: TokenStream) -> TokenStream { ::mingling::macros::register_help!(#entry_type, #struct_name); - // Keep the original function unchanged + // Keep the original function unchanged #(#fn_attrs)* #vis fn #fn_name(#original_inputs) -> #original_return_type { #(#fn_body_stmts)* @@ -176,56 +176,3 @@ fn build_help_entry(struct_name: &Ident, entry_type: &TypePath) -> proc_macro2:: } } } - -pub(crate) fn register_help(input: TokenStream) -> TokenStream { - // Parse the input as a comma-separated list of arguments - let input_parsed = syn::parse_macro_input!(input with syn::punctuated::Punctuated<syn::Expr, syn::Token![,]>::parse_terminated); - - // Check if there are exactly two elements - if input_parsed.len() != 2 { - return syn::Error::new( - input_parsed.span(), - "Expected exactly two comma-separated arguments: `EntryType, StructName`", - ) - .to_compile_error() - .into(); - } - - // Extract the two elements - let entry_type_expr = &input_parsed[0]; - let struct_name_expr = &input_parsed[1]; - - // Convert expressions to TypePath and Ident - let entry_type = match syn::parse2::<TypePath>(entry_type_expr.to_token_stream()) { - Ok(ty) => ty, - Err(e) => return e.to_compile_error().into(), - }; - - let struct_name = match syn::parse2::<syn::Ident>(struct_name_expr.to_token_stream()) { - Ok(ident) => ident, - Err(e) => return e.to_compile_error().into(), - }; - - // Register the help request mapping - let help_entry = build_help_entry(&struct_name, &entry_type); - 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) { - // Already registered by `#[help]`, no duplicate check needed - return 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()) - { - return err.into(); - } - - helps.insert(entry_str); - - quote! {}.into() -} diff --git a/mingling_macros/src/attr/mlint.rs b/mingling_macros/src/attr/mlint.rs new file mode 100644 index 0000000..176ef0a --- /dev/null +++ b/mingling_macros/src/attr/mlint.rs @@ -0,0 +1,7 @@ +use proc_macro::TokenStream; + +/// Marker attribute for the Mingling lint system. +/// All it does is pass the item through unchanged. +pub(crate) fn mlint(_attr: TokenStream, item: TokenStream) -> TokenStream { + item +} |
