From 93fef592b53a4d0c4ec0cdbabc7f65d76903314a Mon Sep 17 00:00:00 2001 From: conectado Date: Tue, 14 Dec 2021 08:14:31 -0300 Subject: [PATCH] chore(rust): fix no_std compilation due to ockam::node attribute Compilation with no_std was failing when main had any return type because of `Executor::execute` signature in no_std. This change fixes it by letting the `Executor::execute` return value bubble up. --- .../ockam/ockam_macros/src/node_attribute/parser.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/implementations/rust/ockam/ockam_macros/src/node_attribute/parser.rs b/implementations/rust/ockam/ockam_macros/src/node_attribute/parser.rs index a0472f47b39..a14383e7280 100644 --- a/implementations/rust/ockam/ockam_macros/src/node_attribute/parser.rs +++ b/implementations/rust/ockam/ockam_macros/src/node_attribute/parser.rs @@ -29,7 +29,17 @@ fn output_node( let err_handling = if ret_type == ReturnType::Default { quote! {.unwrap();} } else { + #[cfg(feature = "std")] quote! {?} + + // For now the executor's `Executor::execute` for std returns `Result` + // while for no_std it returns `Result<()>` and always returns `Ok(())` or panics. + // So while it makes sense using the `?` operator in std in no_std just returning Ok(()) + // would be enough(since execute already hides the return type) but we are letting the + // `Executor::execute` return bubble up to keep the code simpler. + // Note: This also means that for no_std `main` return type can only be `Result<()>` or nothing. + #[cfg(not(feature = "std"))] + quote! {} }; // Assumes the target platform knows about main() functions