aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-05-16 16:28:32 +0800
committer魏曹先生 <1992414357@qq.com>2026-05-16 16:28:32 +0800
commitfab8a28081da10b337b18fcaca98fe64eca7fec7 (patch)
treedbeb5062bc6bbc30d464e4509e6657556e4fa72e
parenta5647e89bc5110a07c8f3c695c3c9582aa31d354 (diff)
Require owned type for first parameter and reference for resources
-rw-r--r--mingling_macros/src/chain.rs15
1 files changed, 13 insertions, 2 deletions
diff --git a/mingling_macros/src/chain.rs b/mingling_macros/src/chain.rs
index 9d3a901..8670f97 100644
--- a/mingling_macros/src/chain.rs
+++ b/mingling_macros/src/chain.rs
@@ -23,13 +23,19 @@ fn extract_args_info(sig: &Signature) -> syn::Result<(Pat, TypePath, Vec<Resourc
));
}
- // First parameter: required, the previous chain type
+ // First parameter: required, the previous chain type (must be owned, not a reference)
let first_arg = &sig.inputs[0];
let (prev_param, previous_type) = match first_arg {
FnArg::Typed(PatType { pat, ty, .. }) => {
let param_pat = (**pat).clone();
match &**ty {
Type::Path(type_path) => (param_pat, type_path.clone()),
+ Type::Reference(_) => {
+ return Err(syn::Error::new(
+ ty.span(),
+ "The first parameter (previous type) must be taken by move, not by reference. Use `prev: SomeEntry` instead of `prev: &SomeEntry`.",
+ ));
+ }
_ => {
return Err(syn::Error::new(
ty.span(),
@@ -79,7 +85,12 @@ fn extract_args_info(sig: &Signature) -> syn::Result<(Pat, TypePath, Vec<Resourc
));
}
},
- Type::Path(type_path) => (type_path.clone(), false, false),
+ Type::Path(_) => {
+ return Err(syn::Error::new(
+ ty.span(),
+ "Resource injection parameter must be a reference (`&T` or `&mut T`), not an owned value. Use `age: &Age` instead of `age: Age`.",
+ ));
+ }
_ => {
return Err(syn::Error::new(
ty.span(),