diff options
author | 2020-10-05 18:26:00 +0000 | |
---|---|---|
committer | 2020-10-05 18:26:00 +0000 | |
commit | 12aa9807c4883e1c8b3f226acea3a6aa5e886989 (patch) | |
tree | 4febd53f9ba370a40e3ee0f3630a3542d1be4964 /macros/src/codegen/init.rs | |
parent | f493f21359ccb3ab4643d9470f3581532f47593a (diff) | |
parent | 8ab7be98714d1ef6298e6feb19f16b84cd9bb4e6 (diff) | |
download | rtic-12aa9807c4883e1c8b3f226acea3a6aa5e886989.tar.gz rtic-12aa9807c4883e1c8b3f226acea3a6aa5e886989.tar.zst rtic-12aa9807c4883e1c8b3f226acea3a6aa5e886989.zip |
Merge #372
372: Now late resources are always used r=AfoHT a=korken89
Awaits the PR in `rtic-syntax`: https://github.com/rtic-rs/rtic-syntax/pull/32
Co-authored-by: Emil Fresk <emil.fresk@gmail.com>
Diffstat (limited to 'macros/src/codegen/init.rs')
-rw-r--r-- | macros/src/codegen/init.rs | 63 |
1 files changed, 27 insertions, 36 deletions
diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index 77d186e5..8942439b 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -36,47 +36,38 @@ pub fn codegen( let mut root_init = vec![]; - let mut user_init_imports = vec![]; - - let ret = { - let late_fields = analysis - .late_resources - .iter() - .flat_map(|resources| { - resources.iter().map(|name| { - let ty = &app.late_resources[name].ty; - let cfgs = &app.late_resources[name].cfgs; - - quote!( + let late_fields = analysis + .late_resources + .iter() + .flat_map(|resources| { + resources.iter().map(|name| { + let ty = &app.late_resources[name].ty; + let cfgs = &app.late_resources[name].cfgs; + + quote!( #(#cfgs)* pub #name: #ty - ) - }) + ) }) - .collect::<Vec<_>>(); + }) + .collect::<Vec<_>>(); - if !late_fields.is_empty() { - let late_resources = util::late_resources_ident(&name); + let mut user_init_imports = vec![]; + let late_resources = util::late_resources_ident(&name); - root_init.push(quote!( - /// Resources initialized at runtime - #[allow(non_snake_case)] - pub struct #late_resources { - #(#late_fields),* - } - )); - - let name_late = format_ident!("{}LateResources", name); - user_init_imports.push(quote!( - #[allow(non_snake_case)] - use super::#name_late; - )); - - Some(quote!(-> #name::LateResources)) - } else { - None + root_init.push(quote!( + /// Resources initialized at runtime + #[allow(non_snake_case)] + pub struct #late_resources { + #(#late_fields),* } - }; + )); + + let name_late = format_ident!("{}LateResources", name); + user_init_imports.push(quote!( + #[allow(non_snake_case)] + use super::#name_late; + )); let mut locals_pat = None; let mut locals_new = None; @@ -95,7 +86,7 @@ pub fn codegen( let user_init = Some(quote!( #(#attrs)* #[allow(non_snake_case)] - fn #name(#(#locals_pat,)* #context: #name::Context) #ret { + fn #name(#(#locals_pat,)* #context: #name::Context) -> #name::LateResources { #(#stmts)* } )); |