Clippy fixes

This commit is contained in:
Emil Fresk 2023-01-08 21:30:53 +01:00 committed by Henrik Tjäder
parent 11f0164448
commit 3cfb95a5db
14 changed files with 43 additions and 63 deletions

View file

@ -19,8 +19,7 @@ fn main() {
&& !(target.starts_with("thumbv6m") | target.starts_with("thumbv8m.base")) && !(target.starts_with("thumbv6m") | target.starts_with("thumbv8m.base"))
{ {
panic!( panic!(
"Unknown target '{}'. Need to update BASEPRI logic in build.rs.", "Unknown target '{target}'. Need to update BASEPRI logic in build.rs."
target
); );
} }

View file

@ -41,8 +41,7 @@ pub fn app(app: &App) -> parse::Result<()> {
let s = { let s = {
format!( format!(
"not enough interrupts to dispatch \ "not enough interrupts to dispatch \
all software tasks (need: {}; given: {})", all software tasks (need: {need}; given: {given})"
need, given
) )
}; };

View file

@ -85,8 +85,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
if level > 0 { if level > 0 {
let doc = format!( let doc = format!(
"Interrupt handler to dispatch async tasks at priority {}", "Interrupt handler to dispatch async tasks at priority {level}"
level
); );
let attribute = &interrupts.get(&level).expect("UNREACHABLE").1.attrs; let attribute = &interrupts.get(&level).expect("UNREACHABLE").1.attrs;
items.push(quote!( items.push(quote!(

View file

@ -15,15 +15,13 @@ pub fn codegen(app: &App, analysis: &Analysis) -> TokenStream2 {
let call_idle = if let Some(idle) = &app.idle { let call_idle = if let Some(idle) = &app.idle {
let name = &idle.name; let name = &idle.name;
quote!(#name(#name::Context::new())) quote!(#name(#name::Context::new()))
} else if analysis.channels.get(&0).is_some() {
let dispatcher = util::zero_prio_dispatcher_ident();
quote!(#dispatcher();)
} else { } else {
if analysis.channels.get(&0).is_some() { quote!(loop {
let dispatcher = util::zero_prio_dispatcher_ident(); rtic::export::nop()
quote!(#dispatcher();) })
} else {
quote!(loop {
rtic::export::nop()
})
}
}; };
let main = util::suffixed("main"); let main = util::suffixed("main");

View file

@ -40,8 +40,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
} }
})) { })) {
let es = format!( let es = format!(
"Maximum priority used by interrupt vector '{}' is more than supported by hardware", "Maximum priority used by interrupt vector '{name}' is more than supported by hardware"
name
); );
// Compile time assert that this priority is supported by the device // Compile time assert that this priority is supported by the device
stmts.push(quote!( stmts.push(quote!(
@ -69,8 +68,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
} }
}) { }) {
let es = format!( let es = format!(
"Maximum priority used by interrupt vector '{}' is more than supported by hardware", "Maximum priority used by interrupt vector '{name}' is more than supported by hardware"
name
); );
// Compile time assert that this priority is supported by the device // Compile time assert that this priority is supported by the device
stmts.push(quote!( stmts.push(quote!(

View file

@ -51,7 +51,7 @@ pub fn impl_mutex(
/// Generates an identifier for the `EXECUTOR_RUN` atomics (`async` API) /// Generates an identifier for the `EXECUTOR_RUN` atomics (`async` API)
pub fn executor_run_ident(task: &Ident) -> Ident { 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 { pub fn interrupt_ident() -> Ident {
@ -78,12 +78,12 @@ pub fn is_exception(name: &Ident) -> bool {
/// Mark a name as internal /// Mark a name as internal
pub fn mark_internal_name(name: &str) -> Ident { 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 /// Generate an internal identifier for tasks
pub fn internal_task_ident(task: &Ident, ident_name: &str) -> Ident { 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 { 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 /// Generates an identifier for a ready queue, async task version
pub fn rq_async_ident(async_task_name: &Ident) -> Ident { 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 /// Suffixed identifier
@ -163,7 +163,7 @@ pub fn suffixed(name: &str) -> Ident {
} }
pub fn static_shared_resource_ident(name: &Ident) -> 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. /// 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 { 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 { 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 { 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 { pub fn zero_prio_dispatcher_ident() -> Ident {

View file

@ -39,9 +39,8 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
Ok(x) => x, Ok(x) => x,
}; };
match check::app(&app) { if let Err(e) = check::app(&app) {
Err(e) => return e.to_compile_error().into(), return e.to_compile_error().into();
_ => {}
} }
let analysis = analyze::app(analysis, &app); 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 // Try to write the expanded code to disk
if let Some(out_str) = out_dir.to_str() { 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() ts.into()

View file

@ -450,8 +450,7 @@ impl App {
return Err(parse::Error::new( return Err(parse::Error::new(
init.user_shared_struct.span(), init.user_shared_struct.span(),
format!( format!(
"This name and the one defined on `#[shared]` are not the same. Should this be `{}`?", "This name and the one defined on `#[shared]` are not the same. Should this be `{shared_resources_ident}`?"
shared_resources_ident
), ),
)); ));
} }
@ -460,8 +459,7 @@ impl App {
return Err(parse::Error::new( return Err(parse::Error::new(
init.user_local_struct.span(), init.user_local_struct.span(),
format!( format!(
"This name and the one defined on `#[local]` are not the same. Should this be `{}`?", "This name and the one defined on `#[local]` are not the same. Should this be `{local_resources_ident}`?"
local_resources_ident
), ),
)); ));
} }

View file

@ -39,9 +39,8 @@ impl HardwareTask {
Err(parse::Error::new( Err(parse::Error::new(
span, span,
&format!( format!(
"this task handler must have type signature `fn({}::Context)`", "this task handler must have type signature `fn({name}::Context)`"
name
), ),
)) ))
} }
@ -83,9 +82,8 @@ impl HardwareTask {
Err(parse::Error::new( Err(parse::Error::new(
span, span,
&format!( format!(
"this task handler must have type signature `fn({}::Context)`", "this task handler must have type signature `fn({name}::Context)`"
name
), ),
)) ))
} }

View file

@ -34,9 +34,8 @@ impl Idle {
Err(parse::Error::new( Err(parse::Error::new(
item.sig.ident.span(), item.sig.ident.span(),
&format!( format!(
"this `#[idle]` function must have signature `fn({}::Context) -> !`", "this `#[idle]` function must have signature `fn({name}::Context) -> !`"
name
), ),
)) ))
} }

View file

@ -41,9 +41,8 @@ impl Init {
Err(parse::Error::new( Err(parse::Error::new(
span, span,
&format!( format!(
"the `#[init]` function must have signature `fn({}::Context) -> (Shared resources struct, Local resources struct)`", "the `#[init]` function must have signature `fn({name}::Context) -> (Shared resources struct, Local resources struct)`"
name
), ),
)) ))
} }

View file

@ -33,9 +33,8 @@ impl SoftwareTask {
Err(parse::Error::new( Err(parse::Error::new(
span, span,
&format!( format!(
"this task handler must have type signature `async fn({}::Context)`", "this task handler must have type signature `async fn({name}::Context)`"
name
), ),
)) ))
} }
@ -71,9 +70,8 @@ impl SoftwareTask {
Err(parse::Error::new( Err(parse::Error::new(
span, span,
&format!( format!(
"this task handler must have type signature `async fn({}::Context)`", "this task handler must have type signature `async fn({name}::Context)`"
name
), ),
)) ))
} }

View file

@ -234,17 +234,13 @@ pub fn parse_local_resources(content: ParseStream<'_>) -> parse::Result<LocalRes
pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> Option<Box<Pat>> { pub fn parse_inputs(inputs: Punctuated<FnArg, Token![,]>, name: &str) -> Option<Box<Pat>> {
let mut inputs = inputs.into_iter(); let mut inputs = inputs.into_iter();
match inputs.next() { if let Some(FnArg::Typed(first)) = inputs.next() {
Some(FnArg::Typed(first)) => { if type_is_path(&first.ty, &[name, "Context"]) {
if type_is_path(&first.ty, &[name, "Context"]) { // No more inputs
// No more inputs if inputs.next().is_none() {
if inputs.next().is_none() { return Some(first.pat);
return Some(first.pat);
}
} }
} }
_ => {}
} }
None None

View file

@ -298,9 +298,9 @@ pub unsafe fn lock<T, R, const M: usize>(
if ceiling >= 4 { if ceiling >= 4 {
// safe to manipulate outside critical section // safe to manipulate outside critical section
// execute closure under protection of raised system ceiling // execute closure under protection of raised system ceiling
let r = interrupt::free(|_| f(&mut *ptr));
// safe to manipulate outside critical section // safe to manipulate outside critical section
r interrupt::free(|_| f(&mut *ptr))
} else { } else {
// safe to manipulate outside critical section // safe to manipulate outside critical section
let mask = compute_mask(0, ceiling, masks); let mask = compute_mask(0, ceiling, masks);