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

@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Fixed
- Re-export `rtic_core::prelude` as `rtic::mutex::prelude` to allow glob imports + Clippy
- Fix all except `must_use` lints from clippy::pedantic
- Fix dated migration docs for spawn
- Remove obsolete action-rs tool-cache
- Force mdBook to return error codes

View file

@ -4,18 +4,18 @@ fn main() {
let target = env::var("TARGET").unwrap();
if version_check::Channel::read().unwrap().is_nightly() {
println!("cargo:rustc-cfg=rustc_is_nightly")
println!("cargo:rustc-cfg=rustc_is_nightly");
}
if target.starts_with("thumbv6m") {
println!("cargo:rustc-cfg=armv6m")
println!("cargo:rustc-cfg=armv6m");
}
if target.starts_with("thumbv7m")
| target.starts_with("thumbv7em")
| target.starts_with("thumbv8m")
{
println!("cargo:rustc-cfg=armv7m")
println!("cargo:rustc-cfg=armv7m");
}
println!("cargo:rerun-if-changed=build.rs");

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,8 +35,20 @@ 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() {
if res.properties.lock_free {
// Lock free resources of `idle` and `init` get 'static lifetime
let lt = if ctxt.runs_once() {
quote!('static)
} else {
lt = Some(quote!('a));
quote!('a)
};
fields.push(quote!(
#(#cfgs)*
pub #name: &#lt #mut_ #ty
));
} else if access.is_shared() {
lt = Some(quote!('a));
fields.push(quote!(
@ -61,19 +73,6 @@ pub fn codegen(ctxt: Context, needs_lt: &mut bool, app: &App) -> (TokenStream2,
// continue as the value has been filled,
continue;
}
} else {
let lt = if ctxt.runs_once() {
quote!('static)
} else {
lt = Some(quote!('a));
quote!('a)
};
fields.push(quote!(
#(#cfgs)*
pub #name: &#lt #mut_ #ty
));
}
let expr = if access.is_exclusive() {
quote!(&mut *(&mut *#mangled_name.get_mut()).as_mut_ptr())
@ -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,14 +86,13 @@ 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;
@ -95,10 +100,6 @@ pub fn app(args: TokenStream, input: TokenStream) -> TokenStream {
}
}
}
} else {
#[cfg(feature = "debugprint")]
println!("\ntarget/ exists\n");
}
// Try to write the expanded code to disk
if let Some(out_str) = out_dir.to_str() {

View file

@ -1,3 +1,4 @@
#![allow(clippy::inline_always)]
use core::{
cell::Cell,
sync::atomic::{AtomicBool, Ordering},
@ -61,7 +62,7 @@ impl Barrier {
}
pub fn release(&self) {
self.inner.store(true, Ordering::Release)
self.inner.store(true, Ordering::Release);
}
pub fn wait(&self) {
@ -91,7 +92,7 @@ impl Priority {
// These two methods are used by `lock` (see below) but can't be used from the RTIC application
#[inline(always)]
fn set(&self, value: u8) {
self.inner.set(value)
self.inner.set(value);
}
/// Get the current priority
@ -160,7 +161,7 @@ pub unsafe fn lock<T, R>(
}
/// Lock the resource proxy by setting the PRIMASK
/// and running the closure with interrupt::free
/// and running the closure with ``interrupt::free``
///
/// # Safety
///
@ -188,6 +189,7 @@ pub unsafe fn lock<T, R>(
}
#[inline]
#[must_use]
pub fn logical2hw(logical: u8, nvic_prio_bits: u8) -> u8 {
((1 << nvic_prio_bits) - logical) << (8 - nvic_prio_bits)
}

View file

@ -36,6 +36,7 @@
html_favicon_url = "https://raw.githubusercontent.com/rtic-rs/cortex-m-rtic/master/book/en/src/RTIC.svg"
)]
//deny_warnings_placeholder_for_ci
#![allow(clippy::inline_always)]
use cortex_m::{interrupt::InterruptNumber, peripheral::NVIC};
pub use cortex_m_rtic_macros::app;
@ -61,7 +62,7 @@ pub fn pend<I>(interrupt: I)
where
I: InterruptNumber,
{
NVIC::pend(interrupt)
NVIC::pend(interrupt);
}
use core::cell::UnsafeCell;
@ -72,12 +73,12 @@ use core::cell::UnsafeCell;
///
/// Soundness:
/// 1) Unsafe API for internal use only
/// 2) get_mut(&self) -> *mut T
/// 2) ``get_mut(&self) -> *mut T``
/// returns a raw mutable pointer to the inner T
/// casting to &mut T is under control of RTIC
/// RTIC ensures &mut T to be unique under Rust aliasing rules.
///
/// Implementation uses the underlying UnsafeCell<T>
/// Implementation uses the underlying ``UnsafeCell<T>``
/// self.0.get() -> *mut T
///
/// 3) get(&self) -> *const T
@ -85,14 +86,14 @@ use core::cell::UnsafeCell;
/// casting to &T is under control of RTIC
/// RTIC ensures &T to be shared under Rust aliasing rules.
///
/// Implementation uses the underlying UnsafeCell<T>
/// Implementation uses the underlying ``UnsafeCell<T>``
/// self.0.get() -> *mut T, demoted to *const T
///
#[repr(transparent)]
pub struct RacyCell<T>(UnsafeCell<T>);
impl<T> RacyCell<T> {
/// Create a RacyCell
/// Create a ``RacyCell``
#[inline(always)]
pub const fn new(value: T) -> Self {
RacyCell(UnsafeCell::new(value))

View file

@ -17,7 +17,7 @@ where
/// # Safety
///
/// Writing to memory with a transmute in order to enable
/// interrupts of the SysTick timer
/// interrupts of the ``SysTick`` timer
///
/// Enqueue a task without checking if it is full
#[inline]
@ -33,11 +33,8 @@ where
{
// Check if the top contains a non-empty element and if that element is
// greater than nr
let if_heap_max_greater_than_nr = self
.0
.peek()
.map(|head| nr.instant < head.instant)
.unwrap_or(true);
let if_heap_max_greater_than_nr =
self.0.peek().map_or(true, |head| nr.instant < head.instant);
if if_heap_max_greater_than_nr {
if Mono::DISABLE_INTERRUPT_ON_EMPTY_QUEUE && self.0.is_empty() {
@ -92,7 +89,7 @@ where
}
}
/// Dequeue a task from the TimerQueue
/// Dequeue a task from the ``TimerQueue``
pub fn dequeue<F>(&mut self, disable_interrupt: F, mono: &mut Mono) -> Option<(Task, u8)>
where
F: FnOnce(),