From c40c89bb4edc22c4a60d8677c660a9ab7eb47e92 Mon Sep 17 00:00:00 2001 From: Emil Fresk Date: Sun, 8 Jan 2023 21:30:53 +0100 Subject: [PATCH] Clippy fixes --- build.rs | 3 +-- macros/src/check.rs | 3 +-- macros/src/codegen/async_dispatchers.rs | 3 +-- macros/src/codegen/main.rs | 14 ++++++-------- macros/src/codegen/pre_init.rs | 6 ++---- macros/src/codegen/util.rs | 16 ++++++++-------- macros/src/lib.rs | 7 +++---- macros/src/syntax/parse/app.rs | 6 ++---- macros/src/syntax/parse/hardware_task.rs | 10 ++++------ macros/src/syntax/parse/idle.rs | 5 ++--- macros/src/syntax/parse/init.rs | 5 ++--- macros/src/syntax/parse/software_task.rs | 10 ++++------ macros/src/syntax/parse/util.rs | 14 +++++--------- src/export.rs | 4 ++-- 14 files changed, 43 insertions(+), 63 deletions(-) diff --git a/build.rs b/build.rs index ff9ebe35e7..38d2c1866d 100644 --- a/build.rs +++ b/build.rs @@ -19,8 +19,7 @@ fn main() { && !(target.starts_with("thumbv6m") | target.starts_with("thumbv8m.base")) { panic!( - "Unknown target '{}'. Need to update BASEPRI logic in build.rs.", - target + "Unknown target '{target}'. Need to update BASEPRI logic in build.rs." ); } diff --git a/macros/src/check.rs b/macros/src/check.rs index 72d0a27024..a05c82e8a4 100644 --- a/macros/src/check.rs +++ b/macros/src/check.rs @@ -41,8 +41,7 @@ pub fn app(app: &App) -> parse::Result<()> { let s = { format!( "not enough interrupts to dispatch \ - all software tasks (need: {}; given: {})", - need, given + all software tasks (need: {need}; given: {given})" ) }; diff --git a/macros/src/codegen/async_dispatchers.rs b/macros/src/codegen/async_dispatchers.rs index f6408e1edf..be02ad09a1 100644 --- a/macros/src/codegen/async_dispatchers.rs +++ b/macros/src/codegen/async_dispatchers.rs @@ -85,8 +85,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { if level > 0 { let doc = format!( - "Interrupt handler to dispatch async tasks at priority {}", - level + "Interrupt handler to dispatch async tasks at priority {level}" ); let attribute = &interrupts.get(&level).expect("UNREACHABLE").1.attrs; items.push(quote!( diff --git a/macros/src/codegen/main.rs b/macros/src/codegen/main.rs index 8e7138f438..2775d259cf 100644 --- a/macros/src/codegen/main.rs +++ b/macros/src/codegen/main.rs @@ -15,15 +15,13 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 { let call_idle = if let Some(idle) = &app.idle { let name = &idle.name; quote!(#name(#name::Context::new())) + } else if analysis.channels.get(&0).is_some() { + let dispatcher = util::zero_prio_dispatcher_ident(); + quote!(#dispatcher();) } else { - if analysis.channels.get(&0).is_some() { - let dispatcher = util::zero_prio_dispatcher_ident(); - quote!(#dispatcher();) - } else { - quote!(loop { - rtic::export::nop() - }) - } + quote!(loop { + rtic::export::nop() + }) }; let main = util::suffixed("main"); diff --git a/macros/src/codegen/pre_init.rs b/macros/src/codegen/pre_init.rs index 14926888ab..28ba29c0e6 100644 --- a/macros/src/codegen/pre_init.rs +++ b/macros/src/codegen/pre_init.rs @@ -40,8 +40,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { } })) { let es = format!( - "Maximum priority used by interrupt vector '{}' is more than supported by hardware", - name + "Maximum priority used by interrupt vector '{name}' is more than supported by hardware" ); // Compile time assert that this priority is supported by the device stmts.push(quote!( @@ -69,8 +68,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec { } }) { let es = format!( - "Maximum priority used by interrupt vector '{}' is more than supported by hardware", - name + "Maximum priority used by interrupt vector '{name}' is more than supported by hardware" ); // Compile time assert that this priority is supported by the device stmts.push(quote!( diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs index 6552839f76..a0caf0aeef 100644 --- a/macros/src/codegen/util.rs +++ b/macros/src/codegen/util.rs @@ -51,7 +51,7 @@ pub fn impl_mutex( /// Generates an identifier for the `EXECUTOR_RUN` atomics (`async` API) pub fn executor_run_ident(task: &Ident) -> Ident { - mark_internal_name(&format!("{}_EXECUTOR_RUN", task)) + mark_internal_name(&format!("{task}_EXECUTOR_RUN")) } pub fn interrupt_ident() -> Ident { @@ -78,12 +78,12 @@ pub fn is_exception(name: &Ident) -> bool { /// Mark a name as internal pub fn mark_internal_name(name: &str) -> Ident { - Ident::new(&format!("{}_{}", RTIC_INTERNAL, name), Span::call_site()) + Ident::new(&format!("{RTIC_INTERNAL}_{name}"), Span::call_site()) } /// Generate an internal identifier for tasks pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { - mark_internal_name(&format!("{}_{}", task, ident_name)) + mark_internal_name(&format!("{task}_{ident_name}")) } fn link_section_index() -> usize { @@ -153,7 +153,7 @@ pub fn local_resources_ident(ctxt: Context, app: &App) -> Ident { /// Generates an identifier for a ready queue, async task version pub fn rq_async_ident(async_task_name: &Ident) -> Ident { - mark_internal_name(&format!("ASYNC_TASK_{}_RQ", async_task_name)) + mark_internal_name(&format!("ASYNC_TASK_{async_task_name}_RQ")) } /// Suffixed identifier @@ -163,7 +163,7 @@ pub fn suffixed(name: &str) -> Ident { } pub fn static_shared_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("shared_resource_{}", name)) + mark_internal_name(&format!("shared_resource_{name}")) } /// Generates an Ident for the number of 32 bit chunks used for Mask storage. @@ -176,15 +176,15 @@ pub fn priority_masks_ident() -> Ident { } pub fn static_local_resource_ident(name: &Ident) -> Ident { - mark_internal_name(&format!("local_resource_{}", name)) + mark_internal_name(&format!("local_resource_{name}")) } pub fn declared_static_local_resource_ident(name: &Ident, task_name: &Ident) -> Ident { - mark_internal_name(&format!("local_{}_{}", task_name, name)) + mark_internal_name(&format!("local_{task_name}_{name}")) } pub fn need_to_lock_ident(name: &Ident) -> Ident { - Ident::new(&format!("{}_that_needs_to_be_locked", name), name.span()) + Ident::new(&format!("{name}_that_needs_to_be_locked"), name.span()) } pub fn zero_prio_dispatcher_ident() -> Ident { diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 34f2bb619b..a8422d0927 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -39,9 +39,8 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { Ok(x) => x, }; - match check::app(&app) { - Err(e) => return e.to_compile_error().into(), - _ => {} + if let Err(e) = check::app(&app) { + return e.to_compile_error().into(); } let analysis = analyze::app(analysis, &app); @@ -86,7 +85,7 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream { // Try to write the expanded code to disk if let Some(out_str) = out_dir.to_str() { - fs::write(format!("{}/rtic-expansion.rs", out_str), ts.to_string()).ok(); + fs::write(format!("{out_str}/rtic-expansion.rs"), ts.to_string()).ok(); } ts.into() diff --git a/macros/src/syntax/parse/app.rs b/macros/src/syntax/parse/app.rs index 8a9242e91d..e797f75e37 100644 --- a/macros/src/syntax/parse/app.rs +++ b/macros/src/syntax/parse/app.rs @@ -450,8 +450,7 @@ impl App { return Err(parse::Error::new( init.user_shared_struct.span(), format!( - "This name and the one defined on `#[shared]` are not the same. Should this be `{}`?", - shared_resources_ident + "This name and the one defined on `#[shared]` are not the same. Should this be `{shared_resources_ident}`?" ), )); } @@ -460,8 +459,7 @@ impl App { return Err(parse::Error::new( init.user_local_struct.span(), format!( - "This name and the one defined on `#[local]` are not the same. Should this be `{}`?", - local_resources_ident + "This name and the one defined on `#[local]` are not the same. Should this be `{local_resources_ident}`?" ), )); } diff --git a/macros/src/syntax/parse/hardware_task.rs b/macros/src/syntax/parse/hardware_task.rs index ff94bc5190..6207e564f5 100644 --- a/macros/src/syntax/parse/hardware_task.rs +++ b/macros/src/syntax/parse/hardware_task.rs @@ -39,9 +39,8 @@ impl HardwareTask { Err(parse::Error::new( span, - &format!( - "this task handler must have type signature `fn({}::Context)`", - name + format!( + "this task handler must have type signature `fn({name}::Context)`" ), )) } @@ -83,9 +82,8 @@ impl HardwareTask { Err(parse::Error::new( span, - &format!( - "this task handler must have type signature `fn({}::Context)`", - name + format!( + "this task handler must have type signature `fn({name}::Context)`" ), )) } diff --git a/macros/src/syntax/parse/idle.rs b/macros/src/syntax/parse/idle.rs index ffec358fc4..aa2ef5e910 100644 --- a/macros/src/syntax/parse/idle.rs +++ b/macros/src/syntax/parse/idle.rs @@ -34,9 +34,8 @@ impl Idle { Err(parse::Error::new( item.sig.ident.span(), - &format!( - "this `#[idle]` function must have signature `fn({}::Context) -> !`", - name + format!( + "this `#[idle]` function must have signature `fn({name}::Context) -> !`" ), )) } diff --git a/macros/src/syntax/parse/init.rs b/macros/src/syntax/parse/init.rs index 61d35391fb..23130c85ac 100644 --- a/macros/src/syntax/parse/init.rs +++ b/macros/src/syntax/parse/init.rs @@ -41,9 +41,8 @@ impl Init { Err(parse::Error::new( span, - &format!( - "the `#[init]` function must have signature `fn({}::Context) -> (Shared resources struct, Local resources struct)`", - name + format!( + "the `#[init]` function must have signature `fn({name}::Context) -> (Shared resources struct, Local resources struct)`" ), )) } diff --git a/macros/src/syntax/parse/software_task.rs b/macros/src/syntax/parse/software_task.rs index 6be597e8fb..319620a4b0 100644 --- a/macros/src/syntax/parse/software_task.rs +++ b/macros/src/syntax/parse/software_task.rs @@ -33,9 +33,8 @@ impl SoftwareTask { Err(parse::Error::new( span, - &format!( - "this task handler must have type signature `async fn({}::Context)`", - name + format!( + "this task handler must have type signature `async fn({name}::Context)`" ), )) } @@ -71,9 +70,8 @@ impl SoftwareTask { Err(parse::Error::new( span, - &format!( - "this task handler must have type signature `async fn({}::Context)`", - name + format!( + "this task handler must have type signature `async fn({name}::Context)`" ), )) } diff --git a/macros/src/syntax/parse/util.rs b/macros/src/syntax/parse/util.rs index 28c3eac6b6..900ef9d66f 100644 --- a/macros/src/syntax/parse/util.rs +++ b/macros/src/syntax/parse/util.rs @@ -234,17 +234,13 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result, name: &str) -> Option> { let mut inputs = inputs.into_iter(); - match inputs.next() { - Some(FnArg::Typed(first)) => { - if type_is_path(&first.ty, &[name, "Context"]) { - // No more inputs - if inputs.next().is_none() { - return Some(first.pat); - } + if let Some(FnArg::Typed(first)) = inputs.next() { + if type_is_path(&first.ty, &[name, "Context"]) { + // No more inputs + if inputs.next().is_none() { + return Some(first.pat); } } - - _ => {} } None diff --git a/src/export.rs b/src/export.rs index bfd0f6dda1..091cfb87ce 100644 --- a/src/export.rs +++ b/src/export.rs @@ -298,9 +298,9 @@ pub unsafe fn lock( if ceiling >= 4 { // safe to manipulate outside critical section // execute closure under protection of raised system ceiling - let r = interrupt::free(|_| f(&mut *ptr)); + // safe to manipulate outside critical section - r + interrupt::free(|_| f(&mut *ptr)) } else { // safe to manipulate outside critical section let mask = compute_mask(0, ceiling, masks);