aboutsummaryrefslogtreecommitdiff
path: root/macros/src/codegen
diff options
context:
space:
mode:
authorGravatar Henrik Tjäder <henrik@tjaders.com> 2020-10-13 14:16:33 +0000
committerGravatar Henrik Tjäder <henrik@tjaders.com> 2020-10-15 17:09:27 +0000
commit21253297e4a11a1d9f9c5069578cf9c69a3de31b (patch)
tree896d527bfd204f788eacc3dc791966fb88e287be /macros/src/codegen
parent355cb82d0693fe108ac28ec8a0d77e8aab4e6e06 (diff)
downloadrtic-21253297e4a11a1d9f9c5069578cf9c69a3de31b.tar.gz
rtic-21253297e4a11a1d9f9c5069578cf9c69a3de31b.tar.zst
rtic-21253297e4a11a1d9f9c5069578cf9c69a3de31b.zip
Implement all clippy suggestions
Diffstat (limited to 'macros/src/codegen')
-rw-r--r--macros/src/codegen/idle.rs2
-rw-r--r--macros/src/codegen/init.rs14
-rw-r--r--macros/src/codegen/post_init.rs2
-rw-r--r--macros/src/codegen/software_tasks.rs2
-rw-r--r--macros/src/codegen/timer_queue.rs4
-rw-r--r--macros/src/codegen/util.rs21
6 files changed, 24 insertions, 21 deletions
diff --git a/macros/src/codegen/idle.rs b/macros/src/codegen/idle.rs
index 5e73329f..72c42a35 100644
--- a/macros/src/codegen/idle.rs
+++ b/macros/src/codegen/idle.rs
@@ -28,7 +28,7 @@ pub fn codegen(
// call_idle
TokenStream2,
) {
- if app.idles.len() > 0 {
+ if !app.idles.is_empty() {
let idle = &app.idles.first().unwrap();
let mut needs_lt = false;
let mut mod_app = None;
diff --git a/macros/src/codegen/init.rs b/macros/src/codegen/init.rs
index 465a927d..1746bff6 100644
--- a/macros/src/codegen/init.rs
+++ b/macros/src/codegen/init.rs
@@ -8,12 +8,7 @@ use crate::{
codegen::{locals, module, resources_struct, util},
};
-/// Generates support code for `#[init]` functions
-pub fn codegen(
- app: &App,
- analysis: &Analysis,
- extra: &Extra,
-) -> (
+type CodegenResult = (
// mod_app_idle -- the `${init}Resources` constructor
Option<TokenStream2>,
// root_init -- items that must be placed in the root of the crate:
@@ -28,8 +23,11 @@ pub fn codegen(
Vec<TokenStream2>,
// call_init -- the call to the user `#[init]` if there's one
Option<TokenStream2>,
-) {
- if app.inits.len() > 0 {
+);
+
+/// Generates support code for `#[init]` functions
+pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> CodegenResult {
+ if !app.inits.is_empty() {
let init = &app.inits.first().unwrap();
let mut needs_lt = false;
let name = &init.name;
diff --git a/macros/src/codegen/post_init.rs b/macros/src/codegen/post_init.rs
index c35c6976..329d700e 100644
--- a/macros/src/codegen/post_init.rs
+++ b/macros/src/codegen/post_init.rs
@@ -9,7 +9,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
let mut stmts = vec![];
// Initialize late resources
- if analysis.late_resources.len() > 0 {
+ if !analysis.late_resources.is_empty() {
// BTreeSet wrapped in a vector
for name in analysis.late_resources.first().unwrap() {
// If it's live
diff --git a/macros/src/codegen/software_tasks.rs b/macros/src/codegen/software_tasks.rs
index 9918dea1..17d1e6da 100644
--- a/macros/src/codegen/software_tasks.rs
+++ b/macros/src/codegen/software_tasks.rs
@@ -56,7 +56,7 @@ pub fn codegen(
pub static mut #fq: #fq_ty = #fq_expr;
));
- let ref elems = (0..cap)
+ let elems = &(0..cap)
.map(|_| quote!(core::mem::MaybeUninit::uninit()))
.collect::<Vec<_>>();
diff --git a/macros/src/codegen/timer_queue.rs b/macros/src/codegen/timer_queue.rs
index c898a7fd..63d72dd9 100644
--- a/macros/src/codegen/timer_queue.rs
+++ b/macros/src/codegen/timer_queue.rs
@@ -26,7 +26,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
})
.collect::<Vec<_>>();
- let doc = format!("Tasks that can be scheduled");
+ let doc = "Tasks that can be scheduled".to_string();
items.push(quote!(
#[doc = #doc]
#[allow(non_camel_case_types)]
@@ -41,7 +41,7 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
// Static variable and resource proxy
{
- let doc = format!("Timer queue");
+ let doc = "Timer queue".to_string();
let cap = app
.software_tasks
.iter()
diff --git a/macros/src/codegen/util.rs b/macros/src/codegen/util.rs
index f04ccb23..bc8bfb8d 100644
--- a/macros/src/codegen/util.rs
+++ b/macros/src/codegen/util.rs
@@ -90,12 +90,17 @@ pub fn interrupt_ident() -> Ident {
pub fn is_exception(name: &Ident) -> bool {
let s = name.to_string();
- match &*s {
- "MemoryManagement" | "BusFault" | "UsageFault" | "SecureFault" | "SVCall"
- | "DebugMonitor" | "PendSV" | "SysTick" => true,
-
- _ => false,
- }
+ matches!(
+ &*s,
+ "MemoryManagement"
+ | "BusFault"
+ | "UsageFault"
+ | "SecureFault"
+ | "SVCall"
+ | "DebugMonitor"
+ | "PendSV"
+ | "SysTick"
+ )
}
/// Generates a pre-reexport identifier for the "late resources" struct
@@ -209,7 +214,7 @@ pub fn rq_ident(priority: u8) -> Ident {
/// Generates an identifier for the `enum` of `schedule`-able tasks
pub fn schedule_t_ident() -> Ident {
- Ident::new(&format!("SCHED_T"), Span::call_site())
+ Ident::new(&"SCHED_T".to_string(), Span::call_site())
}
/// Generates an identifier for the `enum` of `spawn`-able tasks
@@ -229,5 +234,5 @@ pub fn suffixed(name: &str) -> Ident {
///
/// At most there is one timer queue
pub fn tq_ident() -> Ident {
- Ident::new(&format!("TQ"), Span::call_site())
+ Ident::new(&"TQ".to_string(), Span::call_site())
}