Summary
When a pub fn inside a #[contractimpl] block is annotated with #[cfg(test)], the macro correctly propagates that attribute onto the generated __Contract__<method>__invoke_raw_slice function (via #(#attrs)* passthrough in derive_fn). However, derive_contract_function_registration_ctor only received method idents — not their attributes — so the generated registration ctor referenced __Contract__<method>__invoke_raw_slice unconditionally. In a non-test build with the testutils feature enabled, this produces:
error[E0425]: cannot find value `__Contract__persisted__invoke_raw_slice` in this scope
Fix
Change derive_contract_function_registration_ctor to accept (&Ident, &[Attribute]) pairs instead of just &Ident. For each method, extract any cfg attributes and emit them on the corresponding registration call in the ctor body, so #[cfg(test)] (and other cfg guards) are respected.
Impact
Narrow compile-time only: any crate with a #[cfg(test)] public method inside #[contractimpl] would fail to compile with testutils enabled. No runtime behavior is affected.
🤖 Generated with Claude Code
Summary
When a
pub fninside a#[contractimpl]block is annotated with#[cfg(test)], the macro correctly propagates that attribute onto the generated__Contract__<method>__invoke_raw_slicefunction (via#(#attrs)*passthrough inderive_fn). However,derive_contract_function_registration_ctoronly received method idents — not their attributes — so the generated registration ctor referenced__Contract__<method>__invoke_raw_sliceunconditionally. In a non-test build with thetestutilsfeature enabled, this produces:Fix
Change
derive_contract_function_registration_ctorto accept(&Ident, &[Attribute])pairs instead of just&Ident. For each method, extract anycfgattributes and emit them on the corresponding registration call in the ctor body, so#[cfg(test)](and other cfg guards) are respected.Impact
Narrow compile-time only: any crate with a
#[cfg(test)]public method inside#[contractimpl]would fail to compile withtestutilsenabled. No runtime behavior is affected.🤖 Generated with Claude Code