From 5fe400c006d9d143aa7b977cb13f95e7380754a5 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Sat, 16 May 2026 21:55:55 +0800 Subject: Validate single-segment types in attribute macros --- mingling_macros/src/chain.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'mingling_macros/src/chain.rs') diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs index 8670f97..134b3c2 100644 --- a/mingling_macros/src/chain.rs +++ b/mingling_macros/src/chain.rs @@ -29,7 +29,19 @@ fn extract_args_info(sig: &Signature) -> syn::Result<(Pat, TypePath, Vec { let param_pat = (**pat).clone(); match &**ty { - Type::Path(type_path) => (param_pat, type_path.clone()), + Type::Path(type_path) => { + // Check that the type is a single-segment type (no `::`) + if type_path.path.segments.len() > 1 { + return Err(syn::Error::new( + type_path.span(), + format!( + "The type `{}` in #[chain] function must be a simple single-segment type, e.g. `Empty` instead of `other::Empty`. Qualified paths with `::` are not allowed here.", + quote! { #type_path } + ), + )); + } + (param_pat, type_path.clone()) + } Type::Reference(_) => { return Err(syn::Error::new( ty.span(), -- cgit