diff --git a/.vscode/settings.json b/.vscode/settings.json index a5a656637..2be7ffbe0 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,6 +4,7 @@ "rust-analyzer.assist.importGranularity": "module", "rust-analyzer.checkOnSave.allFeatures": false, "rust-analyzer.checkOnSave.allTargets": false, + "rust-analyzer.checkOnSave.command": "clippy", "rust-analyzer.cargo.noDefaultFeatures": true, "rust-analyzer.checkOnSave.noDefaultFeatures": true, "rust-analyzer.cargo.target": "thumbv7em-none-eabi", diff --git a/embassy-hal-common/src/lib.rs b/embassy-hal-common/src/lib.rs index 01e2d3aee..1af30c6b4 100644 --- a/embassy-hal-common/src/lib.rs +++ b/embassy-hal-common/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![allow(clippy::new_without_default)] // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; diff --git a/embassy-macros/src/lib.rs b/embassy-macros/src/lib.rs index 708eed4cd..da08a59c3 100644 --- a/embassy-macros/src/lib.rs +++ b/embassy-macros/src/lib.rs @@ -118,6 +118,7 @@ pub fn task(args: TokenStream, item: TokenStream) -> TokenStream { use #embassy_path::executor::raw::TaskStorage; #task_fn type F = #impl_ty; + #[allow(clippy::declare_interior_mutable_const)] const NEW_TASK: TaskStorage = TaskStorage::new(); static POOL: [TaskStorage; #pool_size] = [NEW_TASK; #pool_size]; unsafe { TaskStorage::spawn_pool(&POOL, move || task(#arg_names)) } diff --git a/embassy-net/src/lib.rs b/embassy-net/src/lib.rs index 47a3650b0..db2a7ebd4 100644 --- a/embassy-net/src/lib.rs +++ b/embassy-net/src/lib.rs @@ -1,4 +1,5 @@ #![cfg_attr(not(feature = "std"), no_std)] +#![allow(clippy::new_without_default)] // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index f26808cd0..42defdcaf 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs @@ -140,7 +140,7 @@ impl Stack { self.waker.register(cx.waker()); let timestamp = instant_to_smoltcp(Instant::now()); - if let Err(_) = self.iface.poll(&mut self.sockets, timestamp) { + if self.iface.poll(&mut self.sockets, timestamp).is_err() { // If poll() returns error, it may not be done yet, so poll again later. cx.waker().wake_by_ref(); return; @@ -152,18 +152,14 @@ impl Stack { // Print when changed if old_link_up != self.link_up { - if self.link_up { - info!("Link up!"); - } else { - info!("Link down!"); - } + info!("link_up = {:?}", self.link_up); } if old_link_up || self.link_up { self.poll_configurator(timestamp) } - if let Some(poll_at) = self.iface.poll_at(&mut self.sockets, timestamp) { + if let Some(poll_at) = self.iface.poll_at(&self.sockets, timestamp) { let t = Timer::at(instant_from_smoltcp(poll_at)); pin_mut!(t); if t.poll(cx).is_ready() { @@ -215,7 +211,7 @@ pub fn init( let mut res = [0u8; 2]; rand(&mut res); let port = u16::from_le_bytes(res); - if port >= LOCAL_PORT_MIN && port <= LOCAL_PORT_MAX { + if (LOCAL_PORT_MIN..=LOCAL_PORT_MAX).contains(&port) { break port; } }; diff --git a/embassy-net/src/tcp_socket.rs b/embassy-net/src/tcp_socket.rs index 25c8af459..2433771c8 100644 --- a/embassy-net/src/tcp_socket.rs +++ b/embassy-net/src/tcp_socket.rs @@ -130,7 +130,7 @@ impl<'a> AsyncBufRead for TcpSocket<'a> { ) -> Poll> { self.with(|socket| match socket.peek(1 << 30) { // No data ready - Ok(buf) if buf.len() == 0 => { + Ok(buf) if buf.is_empty() => { socket.register_recv_waker(cx.waker()); Poll::Pending } diff --git a/embassy-nrf/src/gpio.rs b/embassy-nrf/src/gpio.rs index be0fac2b0..7896945fb 100644 --- a/embassy-nrf/src/gpio.rs +++ b/embassy-nrf/src/gpio.rs @@ -443,7 +443,7 @@ pub trait OptionalPin: Unborrow + sealed::OptionalPin + Sized { #[inline] fn psel_bits(&self) -> u32 { - self.pin().map_or(1u32 << 31, |pin| Pin::psel_bits(pin)) + self.pin().map_or(1u32 << 31, Pin::psel_bits) } /// Convert from concrete pin type PX_XX to type erased `Option`. diff --git a/embassy-nrf/src/gpiote.rs b/embassy-nrf/src/gpiote.rs index bab49cebb..7ec072ac8 100644 --- a/embassy-nrf/src/gpiote.rs +++ b/embassy-nrf/src/gpiote.rs @@ -22,6 +22,7 @@ pub const PIN_COUNT: usize = 48; #[cfg(not(any(feature = "nrf52833", feature = "nrf52840")))] pub const PIN_COUNT: usize = 32; +#[allow(clippy::declare_interior_mutable_const)] const NEW_AW: AtomicWaker = AtomicWaker::new(); static CHANNEL_WAKERS: [AtomicWaker; CHANNEL_COUNT] = [NEW_AW; CHANNEL_COUNT]; static PORT_WAKERS: [AtomicWaker; PIN_COUNT] = [NEW_AW; PIN_COUNT]; diff --git a/embassy-traits/src/delay.rs b/embassy-traits/src/delay.rs index 31239d319..caa0b100a 100644 --- a/embassy-traits/src/delay.rs +++ b/embassy-traits/src/delay.rs @@ -4,8 +4,8 @@ pub trait Delay { type DelayFuture<'a>: Future + 'a; /// Future that completes after now + millis - fn delay_ms<'a>(&'a mut self, millis: u64) -> Self::DelayFuture<'a>; + fn delay_ms(&mut self, millis: u64) -> Self::DelayFuture<'_>; /// Future that completes after now + micros - fn delay_us<'a>(&'a mut self, micros: u64) -> Self::DelayFuture<'a>; + fn delay_us(&mut self, micros: u64) -> Self::DelayFuture<'_>; } diff --git a/embassy-traits/src/flash.rs b/embassy-traits/src/flash.rs index 5e0a4e39f..94e11dbc5 100644 --- a/embassy-traits/src/flash.rs +++ b/embassy-traits/src/flash.rs @@ -37,7 +37,7 @@ pub trait Flash { /// Erases a single page from the flash device. /// /// address must be a multiple of self.erase_size(). - fn erase<'a>(&'a mut self, address: usize) -> Self::ErasePageFuture<'a>; + fn erase(&mut self, address: usize) -> Self::ErasePageFuture<'_>; /// Returns the total size, in bytes. /// This is not guaranteed to be a power of 2. diff --git a/embassy-traits/src/gpio.rs b/embassy-traits/src/gpio.rs index 9fdb41f56..b8f31fc6c 100644 --- a/embassy-traits/src/gpio.rs +++ b/embassy-traits/src/gpio.rs @@ -8,7 +8,7 @@ pub trait WaitForHigh { /// /// If the pin is already high, the future completes immediately. /// Otherwise, it completes when it becomes high. - fn wait_for_high<'a>(&'a mut self) -> Self::Future<'a>; + fn wait_for_high(&mut self) -> Self::Future<'_>; } /// Wait for a pin to become low. @@ -19,7 +19,7 @@ pub trait WaitForLow { /// /// If the pin is already low, the future completes immediately. /// Otherwise, it completes when it becomes low. - fn wait_for_low<'a>(&'a mut self) -> Self::Future<'a>; + fn wait_for_low(&mut self) -> Self::Future<'_>; } /// Wait for a rising edge (transition from low to high) @@ -27,7 +27,7 @@ pub trait WaitForRisingEdge { type Future<'a>: Future + 'a; /// Wait for a rising edge (transition from low to high) - fn wait_for_rising_edge<'a>(&'a mut self) -> Self::Future<'a>; + fn wait_for_rising_edge(&mut self) -> Self::Future<'_>; } /// Wait for a falling edge (transition from high to low) @@ -35,7 +35,7 @@ pub trait WaitForFallingEdge { type Future<'a>: Future + 'a; /// Wait for a falling edge (transition from high to low) - fn wait_for_falling_edge<'a>(&'a mut self) -> Self::Future<'a>; + fn wait_for_falling_edge(&'_ mut self) -> Self::Future<'_>; } /// Wait for any edge (any transition, high to low or low to high) @@ -43,5 +43,5 @@ pub trait WaitForAnyEdge { type Future<'a>: Future + 'a; /// Wait for any edge (any transition, high to low or low to high) - fn wait_for_any_edge<'a>(&'a mut self) -> Self::Future<'a>; + fn wait_for_any_edge(&mut self) -> Self::Future<'_>; } diff --git a/embassy-traits/src/rng.rs b/embassy-traits/src/rng.rs index 3cc4b2a0b..ac4463ee6 100644 --- a/embassy-traits/src/rng.rs +++ b/embassy-traits/src/rng.rs @@ -26,7 +26,7 @@ impl Random { Self { rng } } - pub async fn next_u8<'a>(&'a mut self, range: u8) -> Result { + pub async fn next_u8(&mut self, range: u8) -> Result { // Lemire's method let t = (-(range as i8) % (range as i8)) as u8; loop { @@ -42,7 +42,7 @@ impl Random { } } - pub async fn next_u16<'a>(&'a mut self, range: u16) -> Result { + pub async fn next_u16(&mut self, range: u16) -> Result { // Lemire's method let t = (-(range as i16) % (range as i16)) as u16; loop { @@ -58,7 +58,7 @@ impl Random { } } - pub async fn next_u32<'a>(&'a mut self, range: u32) -> Result { + pub async fn next_u32(&mut self, range: u32) -> Result { // Lemire's method let t = (-(range as i32) % (range as i32)) as u32; loop { diff --git a/embassy/src/channel/mpsc.rs b/embassy/src/channel/mpsc.rs index 9a57c0b19..12d85a52d 100644 --- a/embassy/src/channel/mpsc.rs +++ b/embassy/src/channel/mpsc.rs @@ -130,7 +130,7 @@ where /// closed by `recv` until they are all consumed. /// /// [`close`]: Self::close - pub fn recv<'m>(&'m mut self) -> RecvFuture<'m, M, T, N> { + pub fn recv(&mut self) -> RecvFuture<'_, M, T, N> { RecvFuture { channel: self.channel, } @@ -469,7 +469,7 @@ impl ChannelState { } Err(message) => { cx.into_iter() - .for_each(|cx| self.set_senders_waker(&cx.waker())); + .for_each(|cx| self.set_senders_waker(cx.waker())); Err(TrySendError::Full(message)) } } @@ -487,7 +487,7 @@ impl ChannelState { fn is_closed_with_context(&mut self, cx: Option<&mut Context<'_>>) -> bool { if self.closed { cx.into_iter() - .for_each(|cx| self.set_senders_waker(&cx.waker())); + .for_each(|cx| self.set_senders_waker(cx.waker())); true } else { false diff --git a/embassy/src/executor/raw/util.rs b/embassy/src/executor/raw/util.rs index ca15b6955..ed5822188 100644 --- a/embassy/src/executor/raw/util.rs +++ b/embassy/src/executor/raw/util.rs @@ -12,6 +12,7 @@ impl UninitCell { (*self.0.as_ptr()).get() } + #[allow(clippy::mut_from_ref)] pub unsafe fn as_mut(&self) -> &mut T { &mut *self.as_mut_ptr() } diff --git a/embassy/src/executor/spawner.rs b/embassy/src/executor/spawner.rs index 908e139ae..f06ac8a63 100644 --- a/embassy/src/executor/spawner.rs +++ b/embassy/src/executor/spawner.rs @@ -95,7 +95,7 @@ impl Spawner { /// fails. This is here to allow conditional use of `defmt::unwrap!` /// without introducing a `defmt` feature in the `embassy_macros` package, /// which would require use of `-Z namespaced-features`. - pub fn must_spawn(&self, token: SpawnToken) -> () { + pub fn must_spawn(&self, token: SpawnToken) { unwrap!(self.spawn(token)); } diff --git a/embassy/src/io/util/read_exact.rs b/embassy/src/io/util/read_exact.rs index 80c9376d5..4eecba4cc 100644 --- a/embassy/src/io/util/read_exact.rs +++ b/embassy/src/io/util/read_exact.rs @@ -39,7 +39,7 @@ impl Future for ReadExact<'_, R> { this.buf[..n].copy_from_slice(&buf[..n]); Pin::new(&mut this.reader).consume(n); { - let (_, rest) = mem::replace(&mut this.buf, &mut []).split_at_mut(n); + let (_, rest) = mem::take(&mut this.buf).split_at_mut(n); this.buf = rest; } } diff --git a/embassy/src/io/util/write_all.rs b/embassy/src/io/util/write_all.rs index 76b6ec092..8a7d9984c 100644 --- a/embassy/src/io/util/write_all.rs +++ b/embassy/src/io/util/write_all.rs @@ -31,7 +31,7 @@ impl Future for WriteAll<'_, W> { while !this.buf.is_empty() { let n = ready!(Pin::new(&mut this.writer).poll_write(cx, this.buf))?; { - let (_, rest) = mem::replace(&mut this.buf, &[]).split_at(n); + let (_, rest) = mem::take(&mut this.buf).split_at(n); this.buf = rest; } if n == 0 { diff --git a/embassy/src/lib.rs b/embassy/src/lib.rs index 2eadefb08..a74d1a514 100644 --- a/embassy/src/lib.rs +++ b/embassy/src/lib.rs @@ -3,6 +3,7 @@ #![feature(const_fn_trait_bound)] #![feature(const_fn_fn_ptr_basics)] #![feature(type_alias_impl_trait)] +#![allow(clippy::new_without_default)] // This mod MUST go first, so that the others see its macros. pub(crate) mod fmt; diff --git a/embassy/src/time/delay.rs b/embassy/src/time/delay.rs index a46ee3a4f..13c2191f6 100644 --- a/embassy/src/time/delay.rs +++ b/embassy/src/time/delay.rs @@ -13,10 +13,10 @@ pub struct Delay; impl crate::traits::delay::Delay for Delay { type DelayFuture<'a> = impl Future + 'a; - fn delay_ms<'a>(&'a mut self, millis: u64) -> Self::DelayFuture<'a> { + fn delay_ms(&mut self, millis: u64) -> Self::DelayFuture<'_> { Timer::after(Duration::from_millis(millis)) } - fn delay_us<'a>(&'a mut self, micros: u64) -> Self::DelayFuture<'a> { + fn delay_us(&mut self, micros: u64) -> Self::DelayFuture<'_> { Timer::after(Duration::from_micros(micros)) } } diff --git a/embassy/src/util/forever.rs b/embassy/src/util/forever.rs index 0432fa51e..e367d2643 100644 --- a/embassy/src/util/forever.rs +++ b/embassy/src/util/forever.rs @@ -45,6 +45,7 @@ impl Forever { /// /// Returns a mutable reference to the stored value. #[inline(always)] + #[allow(clippy::mut_from_ref)] pub fn put(&'static self, val: T) -> &'static mut T { if self .used @@ -63,6 +64,7 @@ impl Forever { } #[inline(always)] + #[allow(clippy::mut_from_ref)] pub fn put_with(&'static self, val: impl FnOnce() -> T) -> &'static mut T { if self .used @@ -81,6 +83,7 @@ impl Forever { } #[inline(always)] + #[allow(clippy::mut_from_ref)] pub unsafe fn steal(&'static self) -> &'static mut T { let p = self.t.get(); let p = (&mut *p).as_mut_ptr(); diff --git a/examples/std/Cargo.toml b/examples/std/Cargo.toml index 3ba495e59..b494cd3be 100644 --- a/examples/std/Cargo.toml +++ b/examples/std/Cargo.toml @@ -15,6 +15,6 @@ futures = { version = "0.3.17", default-features = false, features = ["async-awa log = "0.4.14" nix = "0.22.1" libc = "0.2.101" -clap = { version = "3.0.0-beta.4", features = ["derive"] } +clap = { version = "3.0.0-beta.5", features = ["derive"] } rand_core = { version = "0.6.3", features = ["std"] } heapless = { version = "0.7.5", default-features = false } diff --git a/examples/std/src/bin/net.rs b/examples/std/src/bin/net.rs index c44f1c5b0..8abcc586f 100644 --- a/examples/std/src/bin/net.rs +++ b/examples/std/src/bin/net.rs @@ -1,6 +1,6 @@ #![feature(type_alias_impl_trait)] -use clap::{AppSettings, Clap}; +use clap::Parser; use embassy::executor::{Executor, Spawner}; use embassy::io::AsyncWriteExt; use embassy::util::Forever; @@ -18,9 +18,8 @@ static CONFIG_STATIC: Forever = Forever::new(); static CONFIG_DYNAMIC: Forever = Forever::new(); static NET_RESOURCES: Forever> = Forever::new(); -#[derive(Clap)] +#[derive(Parser)] #[clap(version = "1.0")] -#[clap(setting = AppSettings::ColoredHelp)] struct Opts { /// TAP device name #[clap(long, default_value = "tap0")]