From 14dce96035435b0c9b9dd55da65db17c680aec6a Mon Sep 17 00:00:00 2001 From: Leigh McCulloch <351529+leighmcculloch@users.noreply.github.com> Date: Thu, 14 Nov 2024 14:21:35 +1000 Subject: [PATCH] Allow unnecessary unit expression in ContractArgs functions (#1395) ### What Allow the use of an unnecessary unit expression in ContractArgs functions. ### Why Contract args functions are generated for each function in a contract. They accept a tuple or a unit, and return a tuple or a unit. They provide typing so that developers can build tuples for the args of a contract function with some type safety. They're intended for use in situations where a tuple of args need to be created and passed as a Vec, which happens on occassion. For functions that accept no args, a unit expression is the value returned. The existence of the function and the unit expression disappear during build and are a zero cost construct in this case. For the code generation it is much easier to construct a function that returns either a tuple or a unit, rather than a tuple or nothing. It is also much easier to understand the intent of the functions if they show their return value than omit it in this specific case. The warning has no negative impact in this case, especially because it occurs in generated code. Close #1394 ### Known limitations [TODO or N/A] --- soroban-sdk-macros/src/derive_args.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/soroban-sdk-macros/src/derive_args.rs b/soroban-sdk-macros/src/derive_args.rs index 158f5aa6..05bdb09a 100644 --- a/soroban-sdk-macros/src/derive_args.rs +++ b/soroban-sdk-macros/src/derive_args.rs @@ -79,6 +79,7 @@ pub fn derive_args_impl(name: &str, fns: &[syn_ext::Fn]) -> TokenStream { quote! { #[inline(always)] + #[allow(clippy::unused_unit)] pub fn #fn_ident<#fn_input_lifetime>(#(#fn_input_fn_args),*) -> (#(#fn_input_types,)*) {