Skip to content

Commit

Permalink
refactor: only do lifecycle check once, then its requirements
Browse files Browse the repository at this point in the history
  • Loading branch information
ozwaldorf committed Aug 28, 2022
1 parent ea80ab8 commit 1fef981
Showing 1 changed file with 35 additions and 32 deletions.
67 changes: 35 additions & 32 deletions ic-kit-macros/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(
Expand Down

0 comments on commit 1fef981

Please sign in to comment.