diff --git a/ic-kit-macros/src/entry.rs b/ic-kit-macros/src/entry.rs index fe47507..cc05c1a 100644 --- a/ic-kit-macros/src/entry.rs +++ b/ic-kit-macros/src/entry.rs @@ -95,27 +95,6 @@ pub fn gen_entry_point_code( )); } - if entry_point.is_lifecycle() && !entry_point.is_inspect_message() && return_length > 0 { - return Err(Error::new( - signature.output.span(), - format!("#[{}] function cannot have a return value.", entry_point), - )); - } - - if entry_point.is_lifecycle() && attrs.name.is_some() { - return Err(Error::new( - Span::call_site(), - format!("#[{}] function cannot be renamed.", entry_point), - )); - } - - if entry_point.is_lifecycle() && attrs.hidden.is_some() { - return Err(Error::new( - Span::call_site(), - format!("#[{}] function cannot be hidden.", entry_point), - )); - } - if entry_point.is_inspect_message() && return_length != 1 { return Err(Error::new( Span::call_site(), @@ -126,18 +105,42 @@ pub fn gen_entry_point_code( )); } - if entry_point.is_lifecycle() && attrs.guard.is_some() { - return Err(Error::new( - Span::call_site(), - format!("#[{}] function cannot have a guard", entry_point), - )); - } + // Lifecycle functions have some restrictions + if entry_point.is_lifecycle() { + if !entry_point.is_inspect_message() && return_length > 0 { + return Err(Error::new( + signature.output.span(), + format!("#[{}] function cannot have a return value.", entry_point), + )); + } - if entry_point.is_lifecycle() && is_async { - return Err(Error::new( - Span::call_site(), - format!("#[{}] function cannot be async.", entry_point), - )); + if attrs.name.is_some() { + return Err(Error::new( + Span::call_site(), + format!("#[{}] function cannot be renamed.", entry_point), + )); + } + + if attrs.hidden.is_some() { + return Err(Error::new( + Span::call_site(), + format!("#[{}] function cannot be hidden.", entry_point), + )); + } + + if attrs.guard.is_some() { + return Err(Error::new( + Span::call_site(), + format!("#[{}] function cannot have a guard", entry_point), + )); + } + + if is_async { + return Err(Error::new( + Span::call_site(), + format!("#[{}] function cannot be async.", entry_point), + )); + } } let outer_function_ident = Ident::new(