mirror of
https://github.com/rtic-rs/rtic.git
synced 2025-12-19 06:15:45 +01:00
Lifetime cleanup
This commit is contained in:
parent
511ff675b5
commit
2ad36a6efe
3 changed files with 17 additions and 43 deletions
|
|
@ -9,8 +9,6 @@ use crate::codegen::util;
|
|||
|
||||
/// Generates local resources structs
|
||||
pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
||||
let mut lt = None;
|
||||
|
||||
let resources = match ctxt {
|
||||
Context::Init => &app.init.args.local_resources,
|
||||
Context::Idle => {
|
||||
|
|
@ -28,7 +26,6 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
|||
|
||||
let mut fields = vec![];
|
||||
let mut values = vec![];
|
||||
let mut has_cfgs = false;
|
||||
|
||||
for (name, task_local) in resources {
|
||||
let (cfgs, ty, is_declared) = match task_local {
|
||||
|
|
@ -39,12 +36,9 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
|||
TaskLocal::Declared(r) => (&r.cfgs, &r.ty, true),
|
||||
};
|
||||
|
||||
has_cfgs |= !cfgs.is_empty();
|
||||
|
||||
let lt = if ctxt.runs_once() {
|
||||
quote!('static)
|
||||
} else {
|
||||
lt = Some(quote!('a));
|
||||
quote!('a)
|
||||
};
|
||||
|
||||
|
|
@ -73,17 +67,12 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
|||
));
|
||||
}
|
||||
|
||||
if lt.is_some() {
|
||||
// The struct could end up empty due to `cfg`s leading to an error due to `'a` being unused
|
||||
if has_cfgs {
|
||||
fields.push(quote!(
|
||||
#[doc(hidden)]
|
||||
pub __rtic_internal_marker: ::core::marker::PhantomData<&'a ()>
|
||||
));
|
||||
fields.push(quote!(
|
||||
#[doc(hidden)]
|
||||
pub __rtic_internal_marker: ::core::marker::PhantomData<&'a ()>
|
||||
));
|
||||
|
||||
values.push(quote!(__rtic_internal_marker: ::core::marker::PhantomData));
|
||||
}
|
||||
}
|
||||
values.push(quote!(__rtic_internal_marker: ::core::marker::PhantomData));
|
||||
|
||||
let doc = format!("Local resources `{}` has access to", ctxt.ident(app));
|
||||
let ident = util::local_resources_ident(ctxt, app);
|
||||
|
|
@ -91,13 +80,13 @@ pub fn codegen(ctxt: Context, app: &App) -> (TokenStream2, TokenStream2) {
|
|||
#[allow(non_snake_case)]
|
||||
#[allow(non_camel_case_types)]
|
||||
#[doc = #doc]
|
||||
pub struct #ident<#lt> {
|
||||
pub struct #ident<'a> {
|
||||
#(#fields,)*
|
||||
}
|
||||
);
|
||||
|
||||
let constructor = quote!(
|
||||
impl<#lt> #ident<#lt> {
|
||||
impl<'a> #ident<'a> {
|
||||
#[inline(always)]
|
||||
pub unsafe fn new() -> Self {
|
||||
#ident {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue