Clippy with pedantic suggestions

This commit is contained in:
Henrik Tjäder 2022-02-18 19:38:48 +01:00
parent 57da1e0403
commit 5ed93bd1bf
17 changed files with 84 additions and 84 deletions

View file

@ -34,7 +34,7 @@ pub fn app(analysis: P<analyze::Analysis>, app: &App) -> P<Analysis> {
// map from priorities to interrupts (holding name and attributes)
let interrupts: BTreeMap<Priority, _> = priorities
.iter()
.cloned()
.copied()
.rev()
.zip(&app.args.extern_interrupts)
.map(|(p, (id, ext))| (p, (id.clone(), ext.clone())))

View file

@ -20,6 +20,7 @@ mod software_tasks;
mod timer_queue;
mod util;
#[allow(clippy::too_many_lines)]
pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
let mut mod_app = vec![];
let mut mains = vec![];
@ -142,7 +143,9 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
})
.collect();
let monotonics = if !monotonic_parts.is_empty() {
let monotonics = if monotonic_parts.is_empty() {
quote!()
} else {
quote!(
pub use rtic::Monotonic as _;
@ -151,8 +154,6 @@ pub fn app(app: &App, analysis: &Analysis, extra: &Extra) -> TokenStream2 {
#(#monotonic_parts)*
}
)
} else {
quote!()
};
let rt_err = util::rt_err_ident();

View file

@ -78,7 +78,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
pub __marker__: core::marker::PhantomData<&'a ()>
));
values.push(quote!(__marker__: core::marker::PhantomData))
values.push(quote!(__marker__: core::marker::PhantomData));
}
}

View file

@ -3,6 +3,7 @@ use proc_macro2::TokenStream as TokenStream2;
use quote::quote;
use rtic_syntax::{ast::App, Context};
#[allow(clippy::too_many_lines)]
pub fn codegen(
ctxt: Context,
shared_resources_tick: bool,
@ -50,11 +51,7 @@ pub fn codegen(
values.push(quote!(core));
}
Context::Idle => {}
Context::HardwareTask(_) => {}
Context::SoftwareTask(_) => {}
Context::Idle | Context::HardwareTask(_) | Context::SoftwareTask(_) => {}
}
// if ctxt.has_locals(app) {
@ -438,7 +435,9 @@ pub fn codegen(
}
}
if !items.is_empty() {
if items.is_empty() {
quote!()
} else {
quote!(
#(#items)*
@ -449,7 +448,5 @@ pub fn codegen(
#(#module_items)*
}
)
} else {
quote!()
}
}

View file

@ -48,6 +48,7 @@ pub fn codegen(app: &App, analysis: &Analysis) -> Vec<TokenStream2> {
// let doc = format!(" RTIC internal: {}:{}", file!(), line!());
// stmts.push(quote!(#[doc = #doc]));
#[allow(clippy::cast_possible_truncation)]
let idx = Index {
index: i as u32,
span: Span::call_site(),

View file

@ -41,12 +41,12 @@ pub fn codegen(app: &App, analysis: &Analysis, extra: &Extra) -> Vec<TokenStream
let interrupt_ids = analysis.interrupts.iter().map(|(p, (id, _))| (p, id));
// Unmask interrupts and set their priorities
for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().flat_map(|task| {
if !util::is_exception(&task.args.binds) {
Some((&task.args.priority, &task.args.binds))
} else {
for (&priority, name) in interrupt_ids.chain(app.hardware_tasks.values().filter_map(|task| {
if util::is_exception(&task.args.binds) {
// We do exceptions in another pass
None
} else {
Some((&task.args.priority, &task.args.binds))
}
})) {
// Compile time assert that this priority is supported by the device

View file

@ -75,8 +75,7 @@ pub fn codegen(
);
let ceiling = match analysis.ownerships.get(name) {
Some(Ownership::Owned { priority }) => *priority,
Some(Ownership::CoOwned { priority }) => *priority,
Some(Ownership::Owned { priority } | Ownership::CoOwned { priority }) => *priority,
Some(Ownership::Contended { ceiling }) => *ceiling,
None => 0,
};
@ -89,9 +88,9 @@ pub fn codegen(
cfgs,
true,
&shared_name,
quote!(#ty),
&quote!(#ty),
ceiling,
ptr,
&ptr,
));
}
}

View file

@ -35,33 +35,8 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
let mangled_name = util::static_shared_resource_ident(name);
let shared_name = util::need_to_lock_ident(name);
if !res.properties.lock_free {
if access.is_shared() {
lt = Some(quote!('a));
fields.push(quote!(
#(#cfgs)*
pub #name: &'a #ty
));
} else {
// Resource proxy
lt = Some(quote!('a));
fields.push(quote!(
#(#cfgs)*
pub #name: shared_resources::#shared_name<'a>
));
values.push(quote!(
#(#cfgs)*
#name: shared_resources::#shared_name::new(priority)
));
// continue as the value has been filled,
continue;
}
} else {
if res.properties.lock_free {
// Lock free resources of `idle` and `init` get 'static lifetime
let lt = if ctxt.runs_once() {
quote!('static)
} else {
@ -73,6 +48,30 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
#(#cfgs)*
pub #name: &#lt #mut_ #ty
));
} else if access.is_shared() {
lt = Some(quote!('a));
fields.push(quote!(
#(#cfgs)*
pub #name: &'a #ty
));
} else {
// Resource proxy
lt = Some(quote!('a));
fields.push(quote!(
#(#cfgs)*
pub #name: shared_resources::#shared_name<'a>
));
values.push(quote!(
#(#cfgs)*
#name: shared_resources::#shared_name::new(priority)
));
// continue as the value has been filled,
continue;
}
let expr = if access.is_exclusive() {
@ -97,7 +96,7 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
pub __marker__: core::marker::PhantomData<&'a ()>
));
values.push(quote!(__marker__: core::marker::PhantomData))
values.push(quote!(__marker__: core::marker::PhantomData));
}
}

View file

@ -43,7 +43,7 @@ pub fn codegen(
(
quote!(rtic::export::SCFQ<#cap_lit_p1>),
quote!(rtic::export::Queue::new()),
Box::new(|| util::link_section_uninit()),
Box::new(|| Some(util::link_section_uninit())),
)
};
mod_app.push(quote!(

View file

@ -5,6 +5,7 @@ use rtic_syntax::ast::App;
use crate::{analyze::Analysis, check::Extra, codegen::util};
/// Generates timer queues and timer queue handlers
#[allow(clippy::too_many_lines)]
pub fn codegen(app: &App, analysis: &Analysis, _extra: &Extra) -> Vec<TokenStream2> {
let mut items = vec![];

View file

@ -25,9 +25,9 @@ pub fn impl_mutex(
cfgs: &[Attribute],
resources_prefix: bool,
name: &Ident,
ty: TokenStream2,
ty: &TokenStream2,
ceiling: u8,
ptr: TokenStream2,
ptr: &TokenStream2,
) -> TokenStream2 {
let (path, priority) = if resources_prefix {
(quote!(shared_resources::#name), quote!(self.priority()))
@ -117,11 +117,11 @@ fn link_section_index() -> usize {
INDEX.fetch_add(1, Ordering::Relaxed)
}
// NOTE `None` means in shared memory
pub fn link_section_uninit() -> Option<TokenStream2> {
/// Add `link_section` attribute
pub fn link_section_uninit() -> TokenStream2 {
let section = format!(".uninit.rtic{}", link_section_index());
Some(quote!(#[link_section = #section]))
quote!(#[link_section = #section])
}
// Regroups the inputs of a task

View file

@ -20,7 +20,10 @@ mod tests;
/// Attribute used to declare a RTIC application
///
/// For user documentation see the [RTIC book](https://rtic.rs)
///
/// # Panics
///
/// Should never panic, cargo feeds a path which is later converted to a string
#[proc_macro_attribute]
pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
let mut settings = Settings::default();
@ -61,7 +64,10 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
#[cfg(feature = "debugprint")]
println!("OUT_DIR\n{:#?}", out_str);
if !out_dir.exists() {
if out_dir.exists() {
#[cfg(feature = "debugprint")]
println!("\ntarget/ exists\n");
} else {
// Set out_dir to OUT_DIR
out_dir = Path::new(&out_str);
@ -80,24 +86,19 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
.to_str()
.unwrap()
.starts_with(target_triple_prefix)
//|| path.ends_with(&out_dir_root)
{
if let Some(out) = path.parent() {
out_dir = out;
#[cfg(feature = "debugprint")]
println!("{:#?}\n", out_dir);
break;
} else {
// If no parent, just use it
out_dir = path;
break;
}
// If no parent, just use it
out_dir = path;
break;
}
}
}
} else {
#[cfg(feature = "debugprint")]
println!("\ntarget/ exists\n");
}
// Try to write the expanded code to disk