aboutsummaryrefslogtreecommitdiff
path: root/mingling_macros/src/chain.rs
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-16 21:55:55 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-16 21:55:55 +0800
commit5fe400c006d9d143aa7b977cb13f95e7380754a5 (patch)
tree96eca77fa2c47a1b1e6b4713bfefba41555ee9d2 /mingling_macros/src/chain.rs
parent29cdd6fdbe9dd658bbc6b6694b563b046c0d9f41 (diff)
Validate single-segment types in attribute macros
Diffstat (limited to 'mingling_macros/src/chain.rs')
-rw-r--r--mingling_macros/src/chain.rs14
1 files changed, 13 insertions, 1 deletions
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<Resourc
FnArg::Typed(PatType { pat, ty, .. }) => {
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(),