diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-06-20 01:54:57 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-06-20 01:54:57 +0800 |
| commit | fcfe66875f46e8652170fd190416d796ae30aabc (patch) | |
| tree | 2af968ac8cabcb06337e36c35133313781cd1071 /mingling_macros/src/chain.rs | |
| parent | 78330940bd0fcab6ffbb8b930a1ae88d313a9437 (diff) | |
Remove all explicit program name modes from macrosremoved-shit
Diffstat (limited to 'mingling_macros/src/chain.rs')
| -rw-r--r-- | mingling_macros/src/chain.rs | 45 |
1 files changed, 12 insertions, 33 deletions
diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs index b0ea8ae..fb5999a 100644 --- a/mingling_macros/src/chain.rs +++ b/mingling_macros/src/chain.rs @@ -9,20 +9,6 @@ use quote::{ToTokens, quote}; use syn::spanned::Spanned; use syn::{Ident, ItemFn, Pat, ReturnType, Signature, Type, TypePath, parse_macro_input}; -/// Parses the `#[chain(...)]` attribute arguments. -/// -/// Returns: -/// - `program_path`: the token stream representing the program type -/// - `use_crate_prefix`: whether to use the default crate-defined program path -fn parse_chain_attr_args(attr: TokenStream) -> (proc_macro2::TokenStream, bool) { - if attr.is_empty() { - (crate::default_program_path(), true) - } else { - let path: syn::Path = syn::parse(attr).expect("#[chain(..)] argument must be a path"); - (quote! { #path }, false) - } -} - /// Validates that the return type of the function is `Next`. /// Checks whether the return type is `()` (unit). fn is_unit_return_type(sig: &Signature) -> bool { @@ -226,18 +212,10 @@ fn generate_struct_and_impl( struct_name: &Ident, previous_type: &TypePath, previous_type_str: &proc_macro2::TokenStream, - group_name: &proc_macro2::TokenStream, program_type: &proc_macro2::TokenStream, - use_crate_prefix: bool, proc_fn: &proc_macro2::TokenStream, origin_proc_fn: &proc_macro2::TokenStream, ) -> proc_macro2::TokenStream { - let chain_type = if use_crate_prefix { - program_type - } else { - group_name - }; - quote! { #(#fn_attrs)* #[doc(hidden)] @@ -246,7 +224,7 @@ fn generate_struct_and_impl( ::mingling::macros::register_chain!(#previous_type_str, #struct_name); - impl ::mingling::Chain<#chain_type> for #struct_name { + impl ::mingling::Chain<#program_type> for #struct_name { type Previous = #previous_type; #proc_fn @@ -284,8 +262,15 @@ fn reject_mut_in_async(resources: &[ResourceInjection]) -> Result<(), proc_macro } pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream { - // Parse attribute arguments - let (group_name, use_crate_prefix) = parse_chain_attr_args(attr); + // Reject non-empty attribute arguments; #[chain] must be bare + if !attr.is_empty() { + return syn::Error::new( + attr.into_iter().next().unwrap().span().into(), + "#[chain] does not accept arguments", + ) + .to_compile_error() + .into(); + } // Parse the function item let input_fn = parse_macro_input!(item as ItemFn); @@ -340,12 +325,8 @@ pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream { ); let struct_name = Ident::new(&internal_name, fn_name.span()); - // Determine the program type for the return type - let program_type = if use_crate_prefix { - crate::default_program_path() - } else { - group_name.clone() - }; + // Always use the default crate-defined program path + let program_type = crate::default_program_path(); // Generate the `proc` function let proc_fn = generate_proc_fn( @@ -386,9 +367,7 @@ pub fn chain_attr(attr: TokenStream, item: TokenStream) -> TokenStream { &struct_name, &previous_type, &previous_type_str, - &group_name, &program_type, - use_crate_prefix, &proc_fn, &origin_proc_fn, ); |
