Skip to content

Commit

Permalink
Clean up allow(declare_interior_mutable_const)
Browse files Browse the repository at this point in the history
  • Loading branch information
bugadani committed Sep 20, 2024
1 parent d1fa3c4 commit 4814252
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 49 deletions.
2 changes: 2 additions & 0 deletions esp-hal-embassy/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

- MSRV bump to 1.79 (#2156)

### Fixed

### Removed
Expand Down
2 changes: 1 addition & 1 deletion esp-hal-embassy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "esp-hal-embassy"
version = "0.3.0"
edition = "2021"
rust-version = "1.76.0"
rust-version = "1.79.0"
description = "Embassy support for esp-hal"
repository = "https://github.com/esp-rs/esp-hal"
license = "MIT OR Apache-2.0"
Expand Down
5 changes: 1 addition & 4 deletions esp-hal-embassy/src/time_driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,8 @@ pub(super) struct EmbassyTimer {
alarms: Mutex<[AlarmState; MAX_SUPPORTED_ALARM_COUNT]>,
}

#[allow(clippy::declare_interior_mutable_const)]
const ALARM_STATE_NONE: AlarmState = AlarmState::new();

embassy_time_driver::time_driver_impl!(static DRIVER: EmbassyTimer = EmbassyTimer {
alarms: Mutex::new([ALARM_STATE_NONE; MAX_SUPPORTED_ALARM_COUNT]),
alarms: Mutex::new([const { AlarmState::new() }; MAX_SUPPORTED_ALARM_COUNT]),
});

impl EmbassyTimer {
Expand Down
12 changes: 6 additions & 6 deletions esp-hal/src/gpio/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,13 @@ pub mod rtc_io;

/// Convenience constant for `Option::None` pin

static USER_INTERRUPT_HANDLER: CFnPtr = CFnPtr::NULL;
static USER_INTERRUPT_HANDLER: CFnPtr = CFnPtr::new();

struct CFnPtr(AtomicPtr<()>);
impl CFnPtr {
#[allow(clippy::declare_interior_mutable_const)]
pub const NULL: Self = Self(AtomicPtr::new(core::ptr::null_mut()));
pub const fn new() -> Self {
Self(AtomicPtr::new(core::ptr::null_mut()))
}

pub fn store(&self, f: extern "C" fn()) {
self.0.store(f as *mut (), Ordering::Relaxed);
Expand Down Expand Up @@ -2488,9 +2489,8 @@ mod asynch {

use super::*;

#[allow(clippy::declare_interior_mutable_const)]
const NEW_AW: AtomicWaker = AtomicWaker::new();
pub(super) static PIN_WAKERS: [AtomicWaker; NUM_PINS] = [NEW_AW; NUM_PINS];
pub(super) static PIN_WAKERS: [AtomicWaker; NUM_PINS] =
[const { AtomicWaker::new() }; NUM_PINS];

impl<'d, P> Flex<'d, P>
where
Expand Down
13 changes: 2 additions & 11 deletions esp-hal/src/i2c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,23 +533,14 @@ mod asynch {
task::{Context, Poll},
};

use cfg_if::cfg_if;
use embassy_sync::waitqueue::AtomicWaker;
use embedded_hal::i2c::Operation;
use procmacros::handler;

use super::*;

cfg_if! {
if #[cfg(all(i2c0, i2c1))] {
const NUM_I2C: usize = 2;
} else if #[cfg(i2c0)] {
const NUM_I2C: usize = 1;
}
}
#[allow(clippy::declare_interior_mutable_const)]
const INIT: AtomicWaker = AtomicWaker::new();
static WAKERS: [AtomicWaker; NUM_I2C] = [INIT; NUM_I2C];
const NUM_I2C: usize = 1 + cfg!(i2c1) as usize;
static WAKERS: [AtomicWaker; NUM_I2C] = [const { AtomicWaker::new() }; NUM_I2C];

#[cfg_attr(esp32, allow(dead_code))]
pub(crate) enum Event {
Expand Down
4 changes: 1 addition & 3 deletions esp-hal/src/rmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,7 @@ pub mod asynch {
#[cfg(not(any(esp32, esp32s3)))]
const NUM_CHANNELS: usize = 4;

#[allow(clippy::declare_interior_mutable_const)]
const INIT: AtomicWaker = AtomicWaker::new();
static WAKER: [AtomicWaker; NUM_CHANNELS] = [INIT; NUM_CHANNELS];
static WAKER: [AtomicWaker; NUM_CHANNELS] = [const { AtomicWaker::new() }; NUM_CHANNELS];

#[must_use = "futures do nothing unless you `.await` or poll them"]
pub(crate) struct RmtTxFuture<T>
Expand Down
4 changes: 1 addition & 3 deletions esp-hal/src/timer/systimer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,9 +1026,7 @@ mod asynch {

const NUM_ALARMS: usize = 3;

#[allow(clippy::declare_interior_mutable_const)]
const INIT: AtomicWaker = AtomicWaker::new();
static WAKERS: [AtomicWaker; NUM_ALARMS] = [INIT; NUM_ALARMS];
static WAKERS: [AtomicWaker; NUM_ALARMS] = [const { AtomicWaker::new() }; NUM_ALARMS];

#[must_use = "futures do nothing unless you `.await` or poll them"]
pub(crate) struct AlarmFuture<'a, COMP: Comparator, UNIT: Unit> {
Expand Down
5 changes: 2 additions & 3 deletions esp-hal/src/touch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -536,9 +536,8 @@ mod asynch {

const NUM_TOUCH_PINS: usize = 10;

#[allow(clippy::declare_interior_mutable_const)]
const NEW_AW: AtomicWaker = AtomicWaker::new();
static TOUCH_WAKERS: [AtomicWaker; NUM_TOUCH_PINS] = [NEW_AW; NUM_TOUCH_PINS];
static TOUCH_WAKERS: [AtomicWaker; NUM_TOUCH_PINS] =
[const { AtomicWaker::new() }; NUM_TOUCH_PINS];

// Helper variable to store which pins need handling.
static TOUCHED_PINS: AtomicU16 = AtomicU16::new(0);
Expand Down
7 changes: 3 additions & 4 deletions esp-hal/src/twai/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1641,10 +1641,9 @@ mod asynch {
}
}

const NUM_TWAI: usize = 2;
#[allow(clippy::declare_interior_mutable_const)]
const NEW_STATE: TwaiAsyncState = TwaiAsyncState::new();
pub(crate) static TWAI_STATE: [TwaiAsyncState; NUM_TWAI] = [NEW_STATE; NUM_TWAI];
const NUM_TWAI: usize = 1 + cfg!(twai1) as usize;
pub(crate) static TWAI_STATE: [TwaiAsyncState; NUM_TWAI] =
[const { TwaiAsyncState::new() }; NUM_TWAI];

impl<T> Twai<'_, T, crate::Async>
where
Expand Down
17 changes: 3 additions & 14 deletions esp-hal/src/uart.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1849,28 +1849,17 @@ where
mod asynch {
use core::task::Poll;

use cfg_if::cfg_if;
use embassy_sync::waitqueue::AtomicWaker;
use enumset::{EnumSet, EnumSetType};
use procmacros::handler;

use super::*;
use crate::Async;

cfg_if! {
if #[cfg(all(uart0, uart1, uart2))] {
const NUM_UART: usize = 3;
} else if #[cfg(all(uart0, uart1))] {
const NUM_UART: usize = 2;
} else if #[cfg(uart0)] {
const NUM_UART: usize = 1;
}
}
const NUM_UART: usize = 1 + cfg!(uart1) as usize + cfg!(uart2) as usize;

#[allow(clippy::declare_interior_mutable_const)]
const INIT: AtomicWaker = AtomicWaker::new();
static TX_WAKERS: [AtomicWaker; NUM_UART] = [INIT; NUM_UART];
static RX_WAKERS: [AtomicWaker; NUM_UART] = [INIT; NUM_UART];
static TX_WAKERS: [AtomicWaker; NUM_UART] = [const { AtomicWaker::new() }; NUM_UART];
static RX_WAKERS: [AtomicWaker; NUM_UART] = [const { AtomicWaker::new() }; NUM_UART];

#[derive(EnumSetType, Debug)]
pub(crate) enum TxEvent {
Expand Down

0 comments on commit 4814252

Please sign in to comment.