diff options
author | 2020-10-01 19:38:49 +0200 | |
---|---|---|
committer | 2020-10-01 19:38:49 +0200 | |
commit | e7f0d9c3e3fad77dace2ce63af02559fda46cb73 (patch) | |
tree | 8a6be0817178f5877e546d5e8e29ae6b7589628d /macros/src | |
parent | 4d61437bb4debea5adc578ee072bff3619d8077b (diff) | |
download | rtic-e7f0d9c3e3fad77dace2ce63af02559fda46cb73.tar.gz rtic-e7f0d9c3e3fad77dace2ce63af02559fda46cb73.tar.zst rtic-e7f0d9c3e3fad77dace2ce63af02559fda46cb73.zip |
Now late resources are always used
Diffstat (limited to 'macros/src')
-rw-r--r-- | macros/src/codegen/init.rs | 52 | ||||
-rw-r--r-- | macros/src/codegen/module.rs | 12 |
2 files changed, 27 insertions, 37 deletions
diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs index e0b7d699..b41c3894 100644 --- a/macros/src/codegen/init.rs +++ b/macros/src/codegen/init.rs @@ -34,39 +34,31 @@ pub fn codegen( let mut root_init = 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!( - #(#cfgs)* - pub #name: #ty - ) - }) + 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<_>>(); - - if !late_fields.is_empty() { - let late_resources = util::late_resources_ident(&name); + }) + .collect::<Vec<_>>(); - root_init.push(quote!( - /// Resources initialized at runtime - #[allow(non_snake_case)] - pub struct #late_resources { - #(#late_fields),* - } - )); + let late_resources = util::late_resources_ident(&name); - 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 mut locals_pat = None; let mut locals_new = None; @@ -85,7 +77,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)* } )); diff --git a/macros/src/codegen/module.rs b/macros/src/codegen/module.rs index 863f6c5b..85bab3ab 100644 --- a/macros/src/codegen/module.rs +++ b/macros/src/codegen/module.rs @@ -253,14 +253,12 @@ pub fn codegen(ctxt: Context, resources_tick: bool, app: &App, extra: &Extra) -> if let Context::Init = ctxt { let init = &app.inits.first().unwrap(); - if init.returns_late_resources { - let late_resources = util::late_resources_ident(&init.name); + let late_resources = util::late_resources_ident(&init.name); - items.push(quote!( - #[doc(inline)] - pub use super::#late_resources as LateResources; - )); - } + items.push(quote!( + #[doc(inline)] + pub use super::#late_resources as LateResources; + )); } let doc = match ctxt { |