From e7dc5c0939d30ccba98418c42799c4e39f646d23 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 7 Jun 2021 00:10:54 +0200 Subject: [PATCH 1/3] fmt: make all macros `macro_rules` so scoping is consistent. --- embassy-extras/src/fmt.rs | 213 +++++++++++++++++++++-------- embassy-extras/src/ring_buffer.rs | 2 - embassy-net/src/config/dhcp.rs | 1 - embassy-net/src/config/mod.rs | 1 - embassy-net/src/config/statik.rs | 1 - embassy-net/src/device.rs | 1 - embassy-net/src/fmt.rs | 217 +++++++++++++++++++++--------- embassy-net/src/stack.rs | 1 - embassy-net/src/tcp_socket.rs | 1 - embassy-nrf/src/buffered_uarte.rs | 1 - embassy-nrf/src/fmt.rs | 213 +++++++++++++++++++++-------- embassy-nrf/src/pwm.rs | 1 - embassy-nrf/src/qspi.rs | 1 - embassy-nrf/src/spim.rs | 2 +- embassy-nrf/src/twim.rs | 2 +- embassy-nrf/src/uarte.rs | 1 - embassy-rp/src/dma.rs | 1 - embassy-rp/src/fmt.rs | 217 +++++++++++++++++++++--------- embassy-rp/src/pll.rs | 1 - embassy-stm32/src/dac/v2.rs | 1 - embassy-stm32/src/dma/v2.rs | 1 - embassy-stm32/src/fmt.rs | 213 +++++++++++++++++++++-------- embassy-stm32/src/rcc/h7/mod.rs | 1 - embassy-stm32/src/rcc/h7/pll.rs | 1 - embassy-stm32/src/sdmmc/v2.rs | 7 +- embassy/src/executor/mod.rs | 1 - embassy/src/executor/waker.rs | 4 +- embassy/src/fmt.rs | 213 +++++++++++++++++++++-------- embassy/src/time/mod.rs | 2 - embassy/src/util/drop_bomb.rs | 1 - embassy/src/util/mutex.rs | 2 - embassy/src/util/portal.rs | 1 - embassy/src/util/signal.rs | 1 - 33 files changed, 950 insertions(+), 377 deletions(-) diff --git a/embassy-extras/src/fmt.rs b/embassy-extras/src/fmt.rs index 160642cc..6c5063f7 100644 --- a/embassy-extras/src/fmt.rs +++ b/embassy-extras/src/fmt.rs @@ -1,69 +1,170 @@ #![macro_use] -#![allow(clippy::module_inception)] -#![allow(unused)] +#![allow(unused_macros)] #[cfg(all(feature = "defmt", feature = "log"))] compile_error!("You may not enable both `defmt` and `log` features."); -pub use fmt::*; +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::todo!($($x)*); + #[cfg(feature = "defmt")] + defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::panic!($($x)*); + #[cfg(feature = "defmt")] + defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::trace!($($x)*); + #[cfg(feature = "defmt")] + defmt::trace!($($x)*); + } + }; +} + +macro_rules! debug { + ($($x:tt)*) => { + { + #[cfg(fevature = "log")] + log::debug!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug!($($x)*); + } + }; +} + +macro_rules! info { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::info!($($x)*); + #[cfg(feature = "defmt")] + defmt::info!($($x)*); + } + }; +} + +macro_rules! warn { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::warn!($($x)*); + #[cfg(feature = "defmt")] + defmt::warn!($($x)*); + } + }; +} + +macro_rules! error { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::error!($($x)*); + #[cfg(feature = "defmt")] + defmt::error!($($x)*); + } + }; +} #[cfg(feature = "defmt")] -mod fmt { - pub use defmt::{ - assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, - info, panic, todo, trace, unreachable, unwrap, warn, +macro_rules! unwrap { + ($($x:tt)*) => { + defmt::unwrap!($($x)*) }; } -#[cfg(feature = "log")] -mod fmt { - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - pub use log::{debug, error, info, trace, warn}; -} - -#[cfg(not(any(feature = "defmt", feature = "log")))] -mod fmt { - #![macro_use] - - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - - macro_rules! trace { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! debug { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! info { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! warn { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! error { - ($($msg:expr),+ $(,)?) => { - () - }; - } -} - #[cfg(not(feature = "defmt"))] macro_rules! unwrap { ($arg:expr) => { diff --git a/embassy-extras/src/ring_buffer.rs b/embassy-extras/src/ring_buffer.rs index dafdd958..18795787 100644 --- a/embassy-extras/src/ring_buffer.rs +++ b/embassy-extras/src/ring_buffer.rs @@ -1,5 +1,3 @@ -use crate::fmt::assert; - pub struct RingBuffer<'a> { buf: &'a mut [u8], start: usize, diff --git a/embassy-net/src/config/dhcp.rs b/embassy-net/src/config/dhcp.rs index f0c14432..8bbcd817 100644 --- a/embassy-net/src/config/dhcp.rs +++ b/embassy-net/src/config/dhcp.rs @@ -4,7 +4,6 @@ use smoltcp::time::Instant; use super::*; use crate::device::LinkState; -use crate::fmt::*; use crate::{Interface, SocketSet}; pub struct DhcpConfigurator { diff --git a/embassy-net/src/config/mod.rs b/embassy-net/src/config/mod.rs index 94725dba..0f1886ae 100644 --- a/embassy-net/src/config/mod.rs +++ b/embassy-net/src/config/mod.rs @@ -2,7 +2,6 @@ use heapless::Vec; use smoltcp::time::Instant; use smoltcp::wire::{Ipv4Address, Ipv4Cidr}; -use crate::fmt::*; use crate::{Interface, SocketSet}; mod statik; diff --git a/embassy-net/src/config/statik.rs b/embassy-net/src/config/statik.rs index 912143bf..9a530717 100644 --- a/embassy-net/src/config/statik.rs +++ b/embassy-net/src/config/statik.rs @@ -1,7 +1,6 @@ use smoltcp::time::Instant; use super::*; -use crate::fmt::*; use crate::{Interface, SocketSet}; pub struct StaticConfigurator { diff --git a/embassy-net/src/device.rs b/embassy-net/src/device.rs index 6c06b060..5fcb94ac 100644 --- a/embassy-net/src/device.rs +++ b/embassy-net/src/device.rs @@ -3,7 +3,6 @@ use smoltcp::phy::Device as SmolDevice; use smoltcp::phy::DeviceCapabilities; use smoltcp::time::Instant as SmolInstant; -use crate::fmt::*; use crate::packet_pool::PacketBoxExt; use crate::Result; use crate::{Packet, PacketBox, PacketBuf}; diff --git a/embassy-net/src/fmt.rs b/embassy-net/src/fmt.rs index 4da69766..6c5063f7 100644 --- a/embassy-net/src/fmt.rs +++ b/embassy-net/src/fmt.rs @@ -1,74 +1,171 @@ #![macro_use] +#![allow(unused_macros)] #[cfg(all(feature = "defmt", feature = "log"))] compile_error!("You may not enable both `defmt` and `log` features."); -pub use fmt::*; +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::todo!($($x)*); + #[cfg(feature = "defmt")] + defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::panic!($($x)*); + #[cfg(feature = "defmt")] + defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::trace!($($x)*); + #[cfg(feature = "defmt")] + defmt::trace!($($x)*); + } + }; +} + +macro_rules! debug { + ($($x:tt)*) => { + { + #[cfg(fevature = "log")] + log::debug!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug!($($x)*); + } + }; +} + +macro_rules! info { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::info!($($x)*); + #[cfg(feature = "defmt")] + defmt::info!($($x)*); + } + }; +} + +macro_rules! warn { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::warn!($($x)*); + #[cfg(feature = "defmt")] + defmt::warn!($($x)*); + } + }; +} + +macro_rules! error { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::error!($($x)*); + #[cfg(feature = "defmt")] + defmt::error!($($x)*); + } + }; +} #[cfg(feature = "defmt")] -mod fmt { - pub use defmt::{ - assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, - info, panic, todo, trace, unreachable, unwrap, warn, +macro_rules! unwrap { + ($($x:tt)*) => { + defmt::unwrap!($($x)*) }; } -#[cfg(feature = "log")] -mod fmt { - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - pub use log::{debug, error, info, trace, warn}; -} - -#[cfg(not(any(feature = "defmt", feature = "log")))] -mod fmt { - #![macro_use] - - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - - #[macro_export] - macro_rules! trace { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! debug { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! info { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! warn { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! error { - ($($msg:expr),+ $(,)?) => { - () - }; - } -} - #[cfg(not(feature = "defmt"))] -#[macro_export] macro_rules! unwrap { ($arg:expr) => { match $crate::fmt::Try::into_result($arg) { diff --git a/embassy-net/src/stack.rs b/embassy-net/src/stack.rs index e436beb1..a38f0095 100644 --- a/embassy-net/src/stack.rs +++ b/embassy-net/src/stack.rs @@ -20,7 +20,6 @@ use smoltcp::wire::{IpAddress, IpCidr, Ipv4Address, Ipv4Cidr}; use crate::config::Configurator; use crate::config::Event; use crate::device::{Device, DeviceAdapter, LinkState}; -use crate::fmt::*; use crate::{Interface, SocketSet}; const ADDRESSES_LEN: usize = 1; diff --git a/embassy-net/src/tcp_socket.rs b/embassy-net/src/tcp_socket.rs index 4f43bc61..def4c817 100644 --- a/embassy-net/src/tcp_socket.rs +++ b/embassy-net/src/tcp_socket.rs @@ -11,7 +11,6 @@ use smoltcp::time::Duration; use smoltcp::wire::IpEndpoint; use super::stack::Stack; -use crate::fmt::*; use crate::{Error, Result}; pub struct TcpSocket<'a> { diff --git a/embassy-nrf/src/buffered_uarte.rs b/embassy-nrf/src/buffered_uarte.rs index b4ec7091..d853bda7 100644 --- a/embassy-nrf/src/buffered_uarte.rs +++ b/embassy-nrf/src/buffered_uarte.rs @@ -11,7 +11,6 @@ use embassy_extras::peripheral::{PeripheralMutex, PeripheralState}; use embassy_extras::ring_buffer::RingBuffer; use embassy_extras::{low_power_wait_until, unborrow}; -use crate::fmt::{panic, *}; use crate::gpio::sealed::Pin as _; use crate::gpio::{OptionalPin as GpioOptionalPin, Pin as GpioPin}; use crate::pac; diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs index 160642cc..6c5063f7 100644 --- a/embassy-nrf/src/fmt.rs +++ b/embassy-nrf/src/fmt.rs @@ -1,69 +1,170 @@ #![macro_use] -#![allow(clippy::module_inception)] -#![allow(unused)] +#![allow(unused_macros)] #[cfg(all(feature = "defmt", feature = "log"))] compile_error!("You may not enable both `defmt` and `log` features."); -pub use fmt::*; +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::todo!($($x)*); + #[cfg(feature = "defmt")] + defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::panic!($($x)*); + #[cfg(feature = "defmt")] + defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::trace!($($x)*); + #[cfg(feature = "defmt")] + defmt::trace!($($x)*); + } + }; +} + +macro_rules! debug { + ($($x:tt)*) => { + { + #[cfg(fevature = "log")] + log::debug!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug!($($x)*); + } + }; +} + +macro_rules! info { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::info!($($x)*); + #[cfg(feature = "defmt")] + defmt::info!($($x)*); + } + }; +} + +macro_rules! warn { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::warn!($($x)*); + #[cfg(feature = "defmt")] + defmt::warn!($($x)*); + } + }; +} + +macro_rules! error { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::error!($($x)*); + #[cfg(feature = "defmt")] + defmt::error!($($x)*); + } + }; +} #[cfg(feature = "defmt")] -mod fmt { - pub use defmt::{ - assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, - info, panic, todo, trace, unreachable, unwrap, warn, +macro_rules! unwrap { + ($($x:tt)*) => { + defmt::unwrap!($($x)*) }; } -#[cfg(feature = "log")] -mod fmt { - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - pub use log::{debug, error, info, trace, warn}; -} - -#[cfg(not(any(feature = "defmt", feature = "log")))] -mod fmt { - #![macro_use] - - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - - macro_rules! trace { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! debug { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! info { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! warn { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! error { - ($($msg:expr),+ $(,)?) => { - () - }; - } -} - #[cfg(not(feature = "defmt"))] macro_rules! unwrap { ($arg:expr) => { diff --git a/embassy-nrf/src/pwm.rs b/embassy-nrf/src/pwm.rs index 8fc16a3b..07509aef 100644 --- a/embassy-nrf/src/pwm.rs +++ b/embassy-nrf/src/pwm.rs @@ -6,7 +6,6 @@ use core::sync::atomic::{compiler_fence, Ordering}; use embassy::util::Unborrow; use embassy_extras::unborrow; -use crate::fmt::{unreachable, *}; use crate::gpio::sealed::Pin as _; use crate::gpio::OptionalPin as GpioOptionalPin; use crate::interrupt::Interrupt; diff --git a/embassy-nrf/src/qspi.rs b/embassy-nrf/src/qspi.rs index 882db9d8..42bf8f41 100644 --- a/embassy-nrf/src/qspi.rs +++ b/embassy-nrf/src/qspi.rs @@ -10,7 +10,6 @@ use embassy::util::{AtomicWaker, DropBomb, Unborrow}; use embassy_extras::unborrow; use futures::future::poll_fn; -use crate::fmt::{assert, assert_eq, *}; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, Pin as GpioPin}; use crate::pac; diff --git a/embassy-nrf/src/spim.rs b/embassy-nrf/src/spim.rs index b5e9afbc..47d7c5f9 100644 --- a/embassy-nrf/src/spim.rs +++ b/embassy-nrf/src/spim.rs @@ -11,10 +11,10 @@ use embassy_extras::unborrow; use futures::future::poll_fn; use traits::spi::FullDuplex; +use crate::gpio; use crate::gpio::sealed::Pin as _; use crate::gpio::{OptionalPin, Pin as GpioPin}; use crate::interrupt::Interrupt; -use crate::{fmt::*, gpio}; use crate::{pac, util::slice_in_ram_or}; pub use embedded_hal::spi::{Mode, Phase, Polarity, MODE_0, MODE_1, MODE_2, MODE_3}; diff --git a/embassy-nrf/src/twim.rs b/embassy-nrf/src/twim.rs index 160868d7..5f3c5157 100644 --- a/embassy-nrf/src/twim.rs +++ b/embassy-nrf/src/twim.rs @@ -18,10 +18,10 @@ use futures::future::poll_fn; use traits::i2c::I2c; use crate::chip::{EASY_DMA_SIZE, FORCE_COPY_BUFFER_SIZE}; +use crate::gpio; use crate::gpio::Pin as GpioPin; use crate::pac; use crate::util::{slice_in_ram, slice_in_ram_or}; -use crate::{fmt::*, gpio}; pub enum Frequency { #[doc = "26738688: 100 kbps"] diff --git a/embassy-nrf/src/uarte.rs b/embassy-nrf/src/uarte.rs index 2f6d1a39..de093c7f 100644 --- a/embassy-nrf/src/uarte.rs +++ b/embassy-nrf/src/uarte.rs @@ -13,7 +13,6 @@ use embassy_extras::unborrow; use futures::future::poll_fn; use crate::chip::EASY_DMA_SIZE; -use crate::fmt::{assert, panic, *}; use crate::gpio::sealed::Pin as _; use crate::gpio::{self, OptionalPin as GpioOptionalPin, Pin as GpioPin}; use crate::interrupt::Interrupt; diff --git a/embassy-rp/src/dma.rs b/embassy-rp/src/dma.rs index a74b9b92..235e92d7 100644 --- a/embassy-rp/src/dma.rs +++ b/embassy-rp/src/dma.rs @@ -1,6 +1,5 @@ use core::sync::atomic::{compiler_fence, Ordering}; -use crate::fmt::assert; use crate::pac::dma::vals; use crate::{pac, peripherals}; diff --git a/embassy-rp/src/fmt.rs b/embassy-rp/src/fmt.rs index 4da69766..6c5063f7 100644 --- a/embassy-rp/src/fmt.rs +++ b/embassy-rp/src/fmt.rs @@ -1,74 +1,171 @@ #![macro_use] +#![allow(unused_macros)] #[cfg(all(feature = "defmt", feature = "log"))] compile_error!("You may not enable both `defmt` and `log` features."); -pub use fmt::*; +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::todo!($($x)*); + #[cfg(feature = "defmt")] + defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::panic!($($x)*); + #[cfg(feature = "defmt")] + defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::trace!($($x)*); + #[cfg(feature = "defmt")] + defmt::trace!($($x)*); + } + }; +} + +macro_rules! debug { + ($($x:tt)*) => { + { + #[cfg(fevature = "log")] + log::debug!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug!($($x)*); + } + }; +} + +macro_rules! info { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::info!($($x)*); + #[cfg(feature = "defmt")] + defmt::info!($($x)*); + } + }; +} + +macro_rules! warn { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::warn!($($x)*); + #[cfg(feature = "defmt")] + defmt::warn!($($x)*); + } + }; +} + +macro_rules! error { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::error!($($x)*); + #[cfg(feature = "defmt")] + defmt::error!($($x)*); + } + }; +} #[cfg(feature = "defmt")] -mod fmt { - pub use defmt::{ - assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, - info, panic, todo, trace, unreachable, unwrap, warn, +macro_rules! unwrap { + ($($x:tt)*) => { + defmt::unwrap!($($x)*) }; } -#[cfg(feature = "log")] -mod fmt { - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - pub use log::{debug, error, info, trace, warn}; -} - -#[cfg(not(any(feature = "defmt", feature = "log")))] -mod fmt { - #![macro_use] - - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - - #[macro_export] - macro_rules! trace { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! debug { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! info { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! warn { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - #[macro_export] - macro_rules! error { - ($($msg:expr),+ $(,)?) => { - () - }; - } -} - #[cfg(not(feature = "defmt"))] -#[macro_export] macro_rules! unwrap { ($arg:expr) => { match $crate::fmt::Try::into_result($arg) { diff --git a/embassy-rp/src/pll.rs b/embassy-rp/src/pll.rs index befb368c..13c16baf 100644 --- a/embassy-rp/src/pll.rs +++ b/embassy-rp/src/pll.rs @@ -1,4 +1,3 @@ -use crate::fmt::assert; use crate::pac; const XOSC_MHZ: u32 = 12; diff --git a/embassy-stm32/src/dac/v2.rs b/embassy-stm32/src/dac/v2.rs index a7aad04f..d8c9415b 100644 --- a/embassy-stm32/src/dac/v2.rs +++ b/embassy-stm32/src/dac/v2.rs @@ -1,5 +1,4 @@ use crate::dac::{DacPin, Instance}; -use crate::fmt::*; use crate::gpio::AnyPin; use crate::pac::dac; use core::marker::PhantomData; diff --git a/embassy-stm32/src/dma/v2.rs b/embassy-stm32/src/dma/v2.rs index 5b250546..e7bd6913 100644 --- a/embassy-stm32/src/dma/v2.rs +++ b/embassy-stm32/src/dma/v2.rs @@ -5,7 +5,6 @@ use embassy::util::AtomicWaker; use futures::future::poll_fn; use super::*; -use crate::fmt::assert; use crate::interrupt; use crate::pac; use crate::pac::dma::{regs, vals}; diff --git a/embassy-stm32/src/fmt.rs b/embassy-stm32/src/fmt.rs index 160642cc..6c5063f7 100644 --- a/embassy-stm32/src/fmt.rs +++ b/embassy-stm32/src/fmt.rs @@ -1,69 +1,170 @@ #![macro_use] -#![allow(clippy::module_inception)] -#![allow(unused)] +#![allow(unused_macros)] #[cfg(all(feature = "defmt", feature = "log"))] compile_error!("You may not enable both `defmt` and `log` features."); -pub use fmt::*; +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::todo!($($x)*); + #[cfg(feature = "defmt")] + defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::panic!($($x)*); + #[cfg(feature = "defmt")] + defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::trace!($($x)*); + #[cfg(feature = "defmt")] + defmt::trace!($($x)*); + } + }; +} + +macro_rules! debug { + ($($x:tt)*) => { + { + #[cfg(fevature = "log")] + log::debug!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug!($($x)*); + } + }; +} + +macro_rules! info { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::info!($($x)*); + #[cfg(feature = "defmt")] + defmt::info!($($x)*); + } + }; +} + +macro_rules! warn { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::warn!($($x)*); + #[cfg(feature = "defmt")] + defmt::warn!($($x)*); + } + }; +} + +macro_rules! error { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::error!($($x)*); + #[cfg(feature = "defmt")] + defmt::error!($($x)*); + } + }; +} #[cfg(feature = "defmt")] -mod fmt { - pub use defmt::{ - assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, - info, panic, todo, trace, unreachable, unwrap, warn, +macro_rules! unwrap { + ($($x:tt)*) => { + defmt::unwrap!($($x)*) }; } -#[cfg(feature = "log")] -mod fmt { - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - pub use log::{debug, error, info, trace, warn}; -} - -#[cfg(not(any(feature = "defmt", feature = "log")))] -mod fmt { - #![macro_use] - - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - - macro_rules! trace { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! debug { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! info { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! warn { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! error { - ($($msg:expr),+ $(,)?) => { - () - }; - } -} - #[cfg(not(feature = "defmt"))] macro_rules! unwrap { ($arg:expr) => { diff --git a/embassy-stm32/src/rcc/h7/mod.rs b/embassy-stm32/src/rcc/h7/mod.rs index fbf864bf..57cdd547 100644 --- a/embassy-stm32/src/rcc/h7/mod.rs +++ b/embassy-stm32/src/rcc/h7/mod.rs @@ -2,7 +2,6 @@ use core::marker::PhantomData; use embassy::util::Unborrow; -use crate::fmt::{assert, panic}; use crate::pac::rcc::vals::Timpre; use crate::pac::{DBGMCU, RCC, SYSCFG}; use crate::peripherals; diff --git a/embassy-stm32/src/rcc/h7/pll.rs b/embassy-stm32/src/rcc/h7/pll.rs index af958d09..4c40d84d 100644 --- a/embassy-stm32/src/rcc/h7/pll.rs +++ b/embassy-stm32/src/rcc/h7/pll.rs @@ -1,5 +1,4 @@ use super::{Hertz, RCC}; -use crate::fmt::assert; const VCO_MIN: u32 = 150_000_000; const VCO_MAX: u32 = 420_000_000; diff --git a/embassy-stm32/src/sdmmc/v2.rs b/embassy-stm32/src/sdmmc/v2.rs index 2c7f8ac0..9c7bad4d 100644 --- a/embassy-stm32/src/sdmmc/v2.rs +++ b/embassy-stm32/src/sdmmc/v2.rs @@ -10,7 +10,6 @@ use embassy_extras::unborrow; use futures::future::poll_fn; use sdio_host::{BusWidth, CardCapacity, CardStatus, CurrentState, SDStatus, CID, CSD, OCR, SCR}; -use crate::fmt::*; use crate::interrupt::Interrupt; use crate::pac; use crate::pac::gpio::Gpio; @@ -434,7 +433,7 @@ impl SdmmcInner { BusWidth::One => 0, BusWidth::Four => 1, BusWidth::Eight => 2, - _ => self::panic!("Invalid Bus Width"), + _ => panic!("Invalid Bus Width"), }) }); @@ -637,7 +636,7 @@ impl SdmmcInner { direction: Dir, data_transfer_timeout: u32, ) { - self::assert!(block_size <= 14, "Block size up to 2^14 bytes"); + assert!(block_size <= 14, "Block size up to 2^14 bytes"); let regs = self.0; let dtdir = match direction { @@ -678,7 +677,7 @@ impl SdmmcInner { // Enforce AHB and SDMMC_CK clock relation. See RM0433 Rev 7 // Section 55.5.8 let sdmmc_bus_bandwidth = new_clock.0 * (width as u32); - self::assert!(hclk.0 > 3 * sdmmc_bus_bandwidth / 32); + assert!(hclk.0 > 3 * sdmmc_bus_bandwidth / 32); *clock = new_clock; // NOTE(unsafe) We have exclusive access to the regblock diff --git a/embassy/src/executor/mod.rs b/embassy/src/executor/mod.rs index 8a3a8991..598d4e55 100644 --- a/embassy/src/executor/mod.rs +++ b/embassy/src/executor/mod.rs @@ -9,7 +9,6 @@ mod timer_queue; mod util; mod waker; -use crate::fmt::panic; use crate::interrupt::{Interrupt, InterruptExt}; use crate::time::Alarm; diff --git a/embassy/src/executor/waker.rs b/embassy/src/executor/waker.rs index 050f6a1c..ea5b501f 100644 --- a/embassy/src/executor/waker.rs +++ b/embassy/src/executor/waker.rs @@ -24,7 +24,9 @@ pub(crate) unsafe fn from_task(p: NonNull) -> Waker { pub unsafe fn task_from_waker(waker: &Waker) -> NonNull { let hack: &WakerHack = mem::transmute(waker); - assert_eq!(hack.vtable, &VTABLE); + if hack.vtable != &VTABLE { + panic!("Found waker not created by the embassy executor. Consider enabling the `executor-agnostic` feature on the `embassy` crate.") + } NonNull::new_unchecked(hack.data as *mut TaskHeader) } diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs index 160642cc..6c5063f7 100644 --- a/embassy/src/fmt.rs +++ b/embassy/src/fmt.rs @@ -1,69 +1,170 @@ #![macro_use] -#![allow(clippy::module_inception)] -#![allow(unused)] +#![allow(unused_macros)] #[cfg(all(feature = "defmt", feature = "log"))] compile_error!("You may not enable both `defmt` and `log` features."); -pub use fmt::*; +macro_rules! assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert!($($x)*); + } + }; +} + +macro_rules! assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_eq!($($x)*); + } + }; +} + +macro_rules! assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::assert_ne!($($x)*); + } + }; +} + +macro_rules! debug_assert { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert!($($x)*); + } + }; +} + +macro_rules! debug_assert_eq { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_eq!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_eq!($($x)*); + } + }; +} + +macro_rules! debug_assert_ne { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::debug_assert_ne!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug_assert_ne!($($x)*); + } + }; +} + +macro_rules! todo { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::todo!($($x)*); + #[cfg(feature = "defmt")] + defmt::todo!($($x)*); + } + }; +} + +macro_rules! unreachable { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::unreachable!($($x)*); + #[cfg(feature = "defmt")] + defmt::unreachable!($($x)*); + } + }; +} + +macro_rules! panic { + ($($x:tt)*) => { + { + #[cfg(not(feature = "defmt"))] + core::panic!($($x)*); + #[cfg(feature = "defmt")] + defmt::panic!($($x)*); + } + }; +} + +macro_rules! trace { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::trace!($($x)*); + #[cfg(feature = "defmt")] + defmt::trace!($($x)*); + } + }; +} + +macro_rules! debug { + ($($x:tt)*) => { + { + #[cfg(fevature = "log")] + log::debug!($($x)*); + #[cfg(feature = "defmt")] + defmt::debug!($($x)*); + } + }; +} + +macro_rules! info { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::info!($($x)*); + #[cfg(feature = "defmt")] + defmt::info!($($x)*); + } + }; +} + +macro_rules! warn { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::warn!($($x)*); + #[cfg(feature = "defmt")] + defmt::warn!($($x)*); + } + }; +} + +macro_rules! error { + ($($x:tt)*) => { + { + #[cfg(feature = "log")] + log::error!($($x)*); + #[cfg(feature = "defmt")] + defmt::error!($($x)*); + } + }; +} #[cfg(feature = "defmt")] -mod fmt { - pub use defmt::{ - assert, assert_eq, assert_ne, debug, debug_assert, debug_assert_eq, debug_assert_ne, error, - info, panic, todo, trace, unreachable, unwrap, warn, +macro_rules! unwrap { + ($($x:tt)*) => { + defmt::unwrap!($($x)*) }; } -#[cfg(feature = "log")] -mod fmt { - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - pub use log::{debug, error, info, trace, warn}; -} - -#[cfg(not(any(feature = "defmt", feature = "log")))] -mod fmt { - #![macro_use] - - pub use core::{ - assert, assert_eq, assert_ne, debug_assert, debug_assert_eq, debug_assert_ne, panic, todo, - unreachable, - }; - - macro_rules! trace { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! debug { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! info { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! warn { - ($($msg:expr),+ $(,)?) => { - () - }; - } - - macro_rules! error { - ($($msg:expr),+ $(,)?) => { - () - }; - } -} - #[cfg(not(feature = "defmt"))] macro_rules! unwrap { ($arg:expr) => { diff --git a/embassy/src/time/mod.rs b/embassy/src/time/mod.rs index d7284b7a..21b93d38 100644 --- a/embassy/src/time/mod.rs +++ b/embassy/src/time/mod.rs @@ -10,8 +10,6 @@ pub use duration::Duration; pub use instant::Instant; pub use traits::*; -use crate::fmt::*; - // TODO allow customizing, probably via Cargo features `tick-hz-32768` or something. pub const TICKS_PER_SECOND: u64 = 32768; diff --git a/embassy/src/util/drop_bomb.rs b/embassy/src/util/drop_bomb.rs index 388209a2..efb36a97 100644 --- a/embassy/src/util/drop_bomb.rs +++ b/embassy/src/util/drop_bomb.rs @@ -1,4 +1,3 @@ -use crate::fmt::panic; use core::mem; /// An explosive ordinance that panics if it is improperly disposed of. diff --git a/embassy/src/util/mutex.rs b/embassy/src/util/mutex.rs index 86ab070a..e4b7764c 100644 --- a/embassy/src/util/mutex.rs +++ b/embassy/src/util/mutex.rs @@ -1,8 +1,6 @@ use core::cell::UnsafeCell; use critical_section::CriticalSection; -use crate::fmt::assert; - /// A "mutex" based on critical sections /// /// # Safety diff --git a/embassy/src/util/portal.rs b/embassy/src/util/portal.rs index f4f2824a..8ea48109 100644 --- a/embassy/src/util/portal.rs +++ b/embassy/src/util/portal.rs @@ -1,4 +1,3 @@ -use crate::fmt::panic; use core::cell::UnsafeCell; use core::mem; use core::mem::MaybeUninit; diff --git a/embassy/src/util/signal.rs b/embassy/src/util/signal.rs index 2eefe658..af261c45 100644 --- a/embassy/src/util/signal.rs +++ b/embassy/src/util/signal.rs @@ -9,7 +9,6 @@ use executor::raw::TaskHeader; use ptr::NonNull; use crate::executor; -use crate::fmt::panic; use crate::interrupt::{Interrupt, InterruptExt}; /// Synchronization primitive. Allows creating awaitable signals that may be passed between tasks. From ef1ebefec0c682553213406b3e59a30a79520291 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 7 Jun 2021 03:15:05 +0200 Subject: [PATCH 2/3] fmt: use absolute paths --- embassy-extras/src/fmt.rs | 58 +++++++++++++++++++-------------------- embassy-net/src/fmt.rs | 58 +++++++++++++++++++-------------------- embassy-nrf/src/fmt.rs | 58 +++++++++++++++++++-------------------- embassy-rp/src/fmt.rs | 58 +++++++++++++++++++-------------------- embassy-stm32/src/fmt.rs | 58 +++++++++++++++++++-------------------- embassy/src/fmt.rs | 58 +++++++++++++++++++-------------------- 6 files changed, 174 insertions(+), 174 deletions(-) diff --git a/embassy-extras/src/fmt.rs b/embassy-extras/src/fmt.rs index 6c5063f7..2646c57a 100644 --- a/embassy-extras/src/fmt.rs +++ b/embassy-extras/src/fmt.rs @@ -8,9 +8,9 @@ macro_rules! assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert!($($x)*); + ::core::assert!($($x)*); #[cfg(feature = "defmt")] - defmt::assert!($($x)*); + ::defmt::assert!($($x)*); } }; } @@ -19,9 +19,9 @@ macro_rules! assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_eq!($($x)*); + ::core::assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_eq!($($x)*); + ::defmt::assert_eq!($($x)*); } }; } @@ -30,9 +30,9 @@ macro_rules! assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_ne!($($x)*); + ::core::assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_ne!($($x)*); + ::defmt::assert_ne!($($x)*); } }; } @@ -41,9 +41,9 @@ macro_rules! debug_assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert!($($x)*); + ::core::debug_assert!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert!($($x)*); + ::defmt::debug_assert!($($x)*); } }; } @@ -52,9 +52,9 @@ macro_rules! debug_assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_eq!($($x)*); + ::core::debug_assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_eq!($($x)*); + ::defmt::debug_assert_eq!($($x)*); } }; } @@ -63,9 +63,9 @@ macro_rules! debug_assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_ne!($($x)*); + ::core::debug_assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_ne!($($x)*); + ::defmt::debug_assert_ne!($($x)*); } }; } @@ -74,9 +74,9 @@ macro_rules! todo { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::todo!($($x)*); + ::core::todo!($($x)*); #[cfg(feature = "defmt")] - defmt::todo!($($x)*); + ::defmt::todo!($($x)*); } }; } @@ -85,9 +85,9 @@ macro_rules! unreachable { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::unreachable!($($x)*); + ::core::unreachable!($($x)*); #[cfg(feature = "defmt")] - defmt::unreachable!($($x)*); + ::defmt::unreachable!($($x)*); } }; } @@ -96,9 +96,9 @@ macro_rules! panic { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::panic!($($x)*); + ::core::panic!($($x)*); #[cfg(feature = "defmt")] - defmt::panic!($($x)*); + ::defmt::panic!($($x)*); } }; } @@ -107,9 +107,9 @@ macro_rules! trace { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::trace!($($x)*); + ::log::trace!($($x)*); #[cfg(feature = "defmt")] - defmt::trace!($($x)*); + ::defmt::trace!($($x)*); } }; } @@ -118,9 +118,9 @@ macro_rules! debug { ($($x:tt)*) => { { #[cfg(fevature = "log")] - log::debug!($($x)*); + ::log::debug!($($x)*); #[cfg(feature = "defmt")] - defmt::debug!($($x)*); + ::defmt::debug!($($x)*); } }; } @@ -129,9 +129,9 @@ macro_rules! info { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::info!($($x)*); + ::log::info!($($x)*); #[cfg(feature = "defmt")] - defmt::info!($($x)*); + ::defmt::info!($($x)*); } }; } @@ -140,9 +140,9 @@ macro_rules! warn { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::warn!($($x)*); + ::log::warn!($($x)*); #[cfg(feature = "defmt")] - defmt::warn!($($x)*); + ::defmt::warn!($($x)*); } }; } @@ -151,9 +151,9 @@ macro_rules! error { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::error!($($x)*); + ::log::error!($($x)*); #[cfg(feature = "defmt")] - defmt::error!($($x)*); + ::defmt::error!($($x)*); } }; } @@ -161,7 +161,7 @@ macro_rules! error { #[cfg(feature = "defmt")] macro_rules! unwrap { ($($x:tt)*) => { - defmt::unwrap!($($x)*) + ::defmt::unwrap!($($x)*) }; } diff --git a/embassy-net/src/fmt.rs b/embassy-net/src/fmt.rs index 6c5063f7..2646c57a 100644 --- a/embassy-net/src/fmt.rs +++ b/embassy-net/src/fmt.rs @@ -8,9 +8,9 @@ macro_rules! assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert!($($x)*); + ::core::assert!($($x)*); #[cfg(feature = "defmt")] - defmt::assert!($($x)*); + ::defmt::assert!($($x)*); } }; } @@ -19,9 +19,9 @@ macro_rules! assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_eq!($($x)*); + ::core::assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_eq!($($x)*); + ::defmt::assert_eq!($($x)*); } }; } @@ -30,9 +30,9 @@ macro_rules! assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_ne!($($x)*); + ::core::assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_ne!($($x)*); + ::defmt::assert_ne!($($x)*); } }; } @@ -41,9 +41,9 @@ macro_rules! debug_assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert!($($x)*); + ::core::debug_assert!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert!($($x)*); + ::defmt::debug_assert!($($x)*); } }; } @@ -52,9 +52,9 @@ macro_rules! debug_assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_eq!($($x)*); + ::core::debug_assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_eq!($($x)*); + ::defmt::debug_assert_eq!($($x)*); } }; } @@ -63,9 +63,9 @@ macro_rules! debug_assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_ne!($($x)*); + ::core::debug_assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_ne!($($x)*); + ::defmt::debug_assert_ne!($($x)*); } }; } @@ -74,9 +74,9 @@ macro_rules! todo { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::todo!($($x)*); + ::core::todo!($($x)*); #[cfg(feature = "defmt")] - defmt::todo!($($x)*); + ::defmt::todo!($($x)*); } }; } @@ -85,9 +85,9 @@ macro_rules! unreachable { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::unreachable!($($x)*); + ::core::unreachable!($($x)*); #[cfg(feature = "defmt")] - defmt::unreachable!($($x)*); + ::defmt::unreachable!($($x)*); } }; } @@ -96,9 +96,9 @@ macro_rules! panic { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::panic!($($x)*); + ::core::panic!($($x)*); #[cfg(feature = "defmt")] - defmt::panic!($($x)*); + ::defmt::panic!($($x)*); } }; } @@ -107,9 +107,9 @@ macro_rules! trace { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::trace!($($x)*); + ::log::trace!($($x)*); #[cfg(feature = "defmt")] - defmt::trace!($($x)*); + ::defmt::trace!($($x)*); } }; } @@ -118,9 +118,9 @@ macro_rules! debug { ($($x:tt)*) => { { #[cfg(fevature = "log")] - log::debug!($($x)*); + ::log::debug!($($x)*); #[cfg(feature = "defmt")] - defmt::debug!($($x)*); + ::defmt::debug!($($x)*); } }; } @@ -129,9 +129,9 @@ macro_rules! info { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::info!($($x)*); + ::log::info!($($x)*); #[cfg(feature = "defmt")] - defmt::info!($($x)*); + ::defmt::info!($($x)*); } }; } @@ -140,9 +140,9 @@ macro_rules! warn { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::warn!($($x)*); + ::log::warn!($($x)*); #[cfg(feature = "defmt")] - defmt::warn!($($x)*); + ::defmt::warn!($($x)*); } }; } @@ -151,9 +151,9 @@ macro_rules! error { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::error!($($x)*); + ::log::error!($($x)*); #[cfg(feature = "defmt")] - defmt::error!($($x)*); + ::defmt::error!($($x)*); } }; } @@ -161,7 +161,7 @@ macro_rules! error { #[cfg(feature = "defmt")] macro_rules! unwrap { ($($x:tt)*) => { - defmt::unwrap!($($x)*) + ::defmt::unwrap!($($x)*) }; } diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs index 6c5063f7..2646c57a 100644 --- a/embassy-nrf/src/fmt.rs +++ b/embassy-nrf/src/fmt.rs @@ -8,9 +8,9 @@ macro_rules! assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert!($($x)*); + ::core::assert!($($x)*); #[cfg(feature = "defmt")] - defmt::assert!($($x)*); + ::defmt::assert!($($x)*); } }; } @@ -19,9 +19,9 @@ macro_rules! assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_eq!($($x)*); + ::core::assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_eq!($($x)*); + ::defmt::assert_eq!($($x)*); } }; } @@ -30,9 +30,9 @@ macro_rules! assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_ne!($($x)*); + ::core::assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_ne!($($x)*); + ::defmt::assert_ne!($($x)*); } }; } @@ -41,9 +41,9 @@ macro_rules! debug_assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert!($($x)*); + ::core::debug_assert!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert!($($x)*); + ::defmt::debug_assert!($($x)*); } }; } @@ -52,9 +52,9 @@ macro_rules! debug_assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_eq!($($x)*); + ::core::debug_assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_eq!($($x)*); + ::defmt::debug_assert_eq!($($x)*); } }; } @@ -63,9 +63,9 @@ macro_rules! debug_assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_ne!($($x)*); + ::core::debug_assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_ne!($($x)*); + ::defmt::debug_assert_ne!($($x)*); } }; } @@ -74,9 +74,9 @@ macro_rules! todo { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::todo!($($x)*); + ::core::todo!($($x)*); #[cfg(feature = "defmt")] - defmt::todo!($($x)*); + ::defmt::todo!($($x)*); } }; } @@ -85,9 +85,9 @@ macro_rules! unreachable { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::unreachable!($($x)*); + ::core::unreachable!($($x)*); #[cfg(feature = "defmt")] - defmt::unreachable!($($x)*); + ::defmt::unreachable!($($x)*); } }; } @@ -96,9 +96,9 @@ macro_rules! panic { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::panic!($($x)*); + ::core::panic!($($x)*); #[cfg(feature = "defmt")] - defmt::panic!($($x)*); + ::defmt::panic!($($x)*); } }; } @@ -107,9 +107,9 @@ macro_rules! trace { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::trace!($($x)*); + ::log::trace!($($x)*); #[cfg(feature = "defmt")] - defmt::trace!($($x)*); + ::defmt::trace!($($x)*); } }; } @@ -118,9 +118,9 @@ macro_rules! debug { ($($x:tt)*) => { { #[cfg(fevature = "log")] - log::debug!($($x)*); + ::log::debug!($($x)*); #[cfg(feature = "defmt")] - defmt::debug!($($x)*); + ::defmt::debug!($($x)*); } }; } @@ -129,9 +129,9 @@ macro_rules! info { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::info!($($x)*); + ::log::info!($($x)*); #[cfg(feature = "defmt")] - defmt::info!($($x)*); + ::defmt::info!($($x)*); } }; } @@ -140,9 +140,9 @@ macro_rules! warn { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::warn!($($x)*); + ::log::warn!($($x)*); #[cfg(feature = "defmt")] - defmt::warn!($($x)*); + ::defmt::warn!($($x)*); } }; } @@ -151,9 +151,9 @@ macro_rules! error { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::error!($($x)*); + ::log::error!($($x)*); #[cfg(feature = "defmt")] - defmt::error!($($x)*); + ::defmt::error!($($x)*); } }; } @@ -161,7 +161,7 @@ macro_rules! error { #[cfg(feature = "defmt")] macro_rules! unwrap { ($($x:tt)*) => { - defmt::unwrap!($($x)*) + ::defmt::unwrap!($($x)*) }; } diff --git a/embassy-rp/src/fmt.rs b/embassy-rp/src/fmt.rs index 6c5063f7..2646c57a 100644 --- a/embassy-rp/src/fmt.rs +++ b/embassy-rp/src/fmt.rs @@ -8,9 +8,9 @@ macro_rules! assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert!($($x)*); + ::core::assert!($($x)*); #[cfg(feature = "defmt")] - defmt::assert!($($x)*); + ::defmt::assert!($($x)*); } }; } @@ -19,9 +19,9 @@ macro_rules! assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_eq!($($x)*); + ::core::assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_eq!($($x)*); + ::defmt::assert_eq!($($x)*); } }; } @@ -30,9 +30,9 @@ macro_rules! assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_ne!($($x)*); + ::core::assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_ne!($($x)*); + ::defmt::assert_ne!($($x)*); } }; } @@ -41,9 +41,9 @@ macro_rules! debug_assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert!($($x)*); + ::core::debug_assert!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert!($($x)*); + ::defmt::debug_assert!($($x)*); } }; } @@ -52,9 +52,9 @@ macro_rules! debug_assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_eq!($($x)*); + ::core::debug_assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_eq!($($x)*); + ::defmt::debug_assert_eq!($($x)*); } }; } @@ -63,9 +63,9 @@ macro_rules! debug_assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_ne!($($x)*); + ::core::debug_assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_ne!($($x)*); + ::defmt::debug_assert_ne!($($x)*); } }; } @@ -74,9 +74,9 @@ macro_rules! todo { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::todo!($($x)*); + ::core::todo!($($x)*); #[cfg(feature = "defmt")] - defmt::todo!($($x)*); + ::defmt::todo!($($x)*); } }; } @@ -85,9 +85,9 @@ macro_rules! unreachable { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::unreachable!($($x)*); + ::core::unreachable!($($x)*); #[cfg(feature = "defmt")] - defmt::unreachable!($($x)*); + ::defmt::unreachable!($($x)*); } }; } @@ -96,9 +96,9 @@ macro_rules! panic { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::panic!($($x)*); + ::core::panic!($($x)*); #[cfg(feature = "defmt")] - defmt::panic!($($x)*); + ::defmt::panic!($($x)*); } }; } @@ -107,9 +107,9 @@ macro_rules! trace { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::trace!($($x)*); + ::log::trace!($($x)*); #[cfg(feature = "defmt")] - defmt::trace!($($x)*); + ::defmt::trace!($($x)*); } }; } @@ -118,9 +118,9 @@ macro_rules! debug { ($($x:tt)*) => { { #[cfg(fevature = "log")] - log::debug!($($x)*); + ::log::debug!($($x)*); #[cfg(feature = "defmt")] - defmt::debug!($($x)*); + ::defmt::debug!($($x)*); } }; } @@ -129,9 +129,9 @@ macro_rules! info { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::info!($($x)*); + ::log::info!($($x)*); #[cfg(feature = "defmt")] - defmt::info!($($x)*); + ::defmt::info!($($x)*); } }; } @@ -140,9 +140,9 @@ macro_rules! warn { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::warn!($($x)*); + ::log::warn!($($x)*); #[cfg(feature = "defmt")] - defmt::warn!($($x)*); + ::defmt::warn!($($x)*); } }; } @@ -151,9 +151,9 @@ macro_rules! error { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::error!($($x)*); + ::log::error!($($x)*); #[cfg(feature = "defmt")] - defmt::error!($($x)*); + ::defmt::error!($($x)*); } }; } @@ -161,7 +161,7 @@ macro_rules! error { #[cfg(feature = "defmt")] macro_rules! unwrap { ($($x:tt)*) => { - defmt::unwrap!($($x)*) + ::defmt::unwrap!($($x)*) }; } diff --git a/embassy-stm32/src/fmt.rs b/embassy-stm32/src/fmt.rs index 6c5063f7..2646c57a 100644 --- a/embassy-stm32/src/fmt.rs +++ b/embassy-stm32/src/fmt.rs @@ -8,9 +8,9 @@ macro_rules! assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert!($($x)*); + ::core::assert!($($x)*); #[cfg(feature = "defmt")] - defmt::assert!($($x)*); + ::defmt::assert!($($x)*); } }; } @@ -19,9 +19,9 @@ macro_rules! assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_eq!($($x)*); + ::core::assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_eq!($($x)*); + ::defmt::assert_eq!($($x)*); } }; } @@ -30,9 +30,9 @@ macro_rules! assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_ne!($($x)*); + ::core::assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_ne!($($x)*); + ::defmt::assert_ne!($($x)*); } }; } @@ -41,9 +41,9 @@ macro_rules! debug_assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert!($($x)*); + ::core::debug_assert!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert!($($x)*); + ::defmt::debug_assert!($($x)*); } }; } @@ -52,9 +52,9 @@ macro_rules! debug_assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_eq!($($x)*); + ::core::debug_assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_eq!($($x)*); + ::defmt::debug_assert_eq!($($x)*); } }; } @@ -63,9 +63,9 @@ macro_rules! debug_assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_ne!($($x)*); + ::core::debug_assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_ne!($($x)*); + ::defmt::debug_assert_ne!($($x)*); } }; } @@ -74,9 +74,9 @@ macro_rules! todo { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::todo!($($x)*); + ::core::todo!($($x)*); #[cfg(feature = "defmt")] - defmt::todo!($($x)*); + ::defmt::todo!($($x)*); } }; } @@ -85,9 +85,9 @@ macro_rules! unreachable { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::unreachable!($($x)*); + ::core::unreachable!($($x)*); #[cfg(feature = "defmt")] - defmt::unreachable!($($x)*); + ::defmt::unreachable!($($x)*); } }; } @@ -96,9 +96,9 @@ macro_rules! panic { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::panic!($($x)*); + ::core::panic!($($x)*); #[cfg(feature = "defmt")] - defmt::panic!($($x)*); + ::defmt::panic!($($x)*); } }; } @@ -107,9 +107,9 @@ macro_rules! trace { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::trace!($($x)*); + ::log::trace!($($x)*); #[cfg(feature = "defmt")] - defmt::trace!($($x)*); + ::defmt::trace!($($x)*); } }; } @@ -118,9 +118,9 @@ macro_rules! debug { ($($x:tt)*) => { { #[cfg(fevature = "log")] - log::debug!($($x)*); + ::log::debug!($($x)*); #[cfg(feature = "defmt")] - defmt::debug!($($x)*); + ::defmt::debug!($($x)*); } }; } @@ -129,9 +129,9 @@ macro_rules! info { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::info!($($x)*); + ::log::info!($($x)*); #[cfg(feature = "defmt")] - defmt::info!($($x)*); + ::defmt::info!($($x)*); } }; } @@ -140,9 +140,9 @@ macro_rules! warn { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::warn!($($x)*); + ::log::warn!($($x)*); #[cfg(feature = "defmt")] - defmt::warn!($($x)*); + ::defmt::warn!($($x)*); } }; } @@ -151,9 +151,9 @@ macro_rules! error { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::error!($($x)*); + ::log::error!($($x)*); #[cfg(feature = "defmt")] - defmt::error!($($x)*); + ::defmt::error!($($x)*); } }; } @@ -161,7 +161,7 @@ macro_rules! error { #[cfg(feature = "defmt")] macro_rules! unwrap { ($($x:tt)*) => { - defmt::unwrap!($($x)*) + ::defmt::unwrap!($($x)*) }; } diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs index 6c5063f7..2646c57a 100644 --- a/embassy/src/fmt.rs +++ b/embassy/src/fmt.rs @@ -8,9 +8,9 @@ macro_rules! assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert!($($x)*); + ::core::assert!($($x)*); #[cfg(feature = "defmt")] - defmt::assert!($($x)*); + ::defmt::assert!($($x)*); } }; } @@ -19,9 +19,9 @@ macro_rules! assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_eq!($($x)*); + ::core::assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_eq!($($x)*); + ::defmt::assert_eq!($($x)*); } }; } @@ -30,9 +30,9 @@ macro_rules! assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::assert_ne!($($x)*); + ::core::assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::assert_ne!($($x)*); + ::defmt::assert_ne!($($x)*); } }; } @@ -41,9 +41,9 @@ macro_rules! debug_assert { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert!($($x)*); + ::core::debug_assert!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert!($($x)*); + ::defmt::debug_assert!($($x)*); } }; } @@ -52,9 +52,9 @@ macro_rules! debug_assert_eq { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_eq!($($x)*); + ::core::debug_assert_eq!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_eq!($($x)*); + ::defmt::debug_assert_eq!($($x)*); } }; } @@ -63,9 +63,9 @@ macro_rules! debug_assert_ne { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::debug_assert_ne!($($x)*); + ::core::debug_assert_ne!($($x)*); #[cfg(feature = "defmt")] - defmt::debug_assert_ne!($($x)*); + ::defmt::debug_assert_ne!($($x)*); } }; } @@ -74,9 +74,9 @@ macro_rules! todo { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::todo!($($x)*); + ::core::todo!($($x)*); #[cfg(feature = "defmt")] - defmt::todo!($($x)*); + ::defmt::todo!($($x)*); } }; } @@ -85,9 +85,9 @@ macro_rules! unreachable { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::unreachable!($($x)*); + ::core::unreachable!($($x)*); #[cfg(feature = "defmt")] - defmt::unreachable!($($x)*); + ::defmt::unreachable!($($x)*); } }; } @@ -96,9 +96,9 @@ macro_rules! panic { ($($x:tt)*) => { { #[cfg(not(feature = "defmt"))] - core::panic!($($x)*); + ::core::panic!($($x)*); #[cfg(feature = "defmt")] - defmt::panic!($($x)*); + ::defmt::panic!($($x)*); } }; } @@ -107,9 +107,9 @@ macro_rules! trace { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::trace!($($x)*); + ::log::trace!($($x)*); #[cfg(feature = "defmt")] - defmt::trace!($($x)*); + ::defmt::trace!($($x)*); } }; } @@ -118,9 +118,9 @@ macro_rules! debug { ($($x:tt)*) => { { #[cfg(fevature = "log")] - log::debug!($($x)*); + ::log::debug!($($x)*); #[cfg(feature = "defmt")] - defmt::debug!($($x)*); + ::defmt::debug!($($x)*); } }; } @@ -129,9 +129,9 @@ macro_rules! info { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::info!($($x)*); + ::log::info!($($x)*); #[cfg(feature = "defmt")] - defmt::info!($($x)*); + ::defmt::info!($($x)*); } }; } @@ -140,9 +140,9 @@ macro_rules! warn { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::warn!($($x)*); + ::log::warn!($($x)*); #[cfg(feature = "defmt")] - defmt::warn!($($x)*); + ::defmt::warn!($($x)*); } }; } @@ -151,9 +151,9 @@ macro_rules! error { ($($x:tt)*) => { { #[cfg(feature = "log")] - log::error!($($x)*); + ::log::error!($($x)*); #[cfg(feature = "defmt")] - defmt::error!($($x)*); + ::defmt::error!($($x)*); } }; } @@ -161,7 +161,7 @@ macro_rules! error { #[cfg(feature = "defmt")] macro_rules! unwrap { ($($x:tt)*) => { - defmt::unwrap!($($x)*) + ::defmt::unwrap!($($x)*) }; } From 3be49d3e794d5819574fe33ffbfda9da1ddbe216 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Mon, 7 Jun 2021 03:21:09 +0200 Subject: [PATCH 3/3] fmt: Add dunmy use to avoid "unused variable" errors when no log is enabled. --- .vscode/settings.json | 4 ++-- embassy-extras/src/fmt.rs | 42 ++++++++++++++++++++++++--------------- embassy-net/src/fmt.rs | 42 ++++++++++++++++++++++++--------------- embassy-nrf/src/fmt.rs | 42 ++++++++++++++++++++++++--------------- embassy-rp/src/fmt.rs | 42 ++++++++++++++++++++++++--------------- embassy-stm32/src/fmt.rs | 42 ++++++++++++++++++++++++--------------- embassy/src/fmt.rs | 42 ++++++++++++++++++++++++--------------- stm32-metapac/Cargo.toml | 4 +++- 8 files changed, 161 insertions(+), 99 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 4c6c3bec..ca242662 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,8 +3,8 @@ "editor.formatOnSave": true, "rust-analyzer.checkOnSave.allFeatures": false, "rust-analyzer.checkOnSave.allTargets": false, - //"rust-analyzer.cargo.target": "thumbv7em-none-eabi", - //"rust-analyzer.checkOnSave.target": "thumbv7em-none-eabi", + "rust-analyzer.cargo.target": "thumbv7em-none-eabi", + "rust-analyzer.checkOnSave.target": "thumbv7em-none-eabi", "rust-analyzer.procMacro.enable": true, "rust-analyzer.cargo.loadOutDirsFromCheck": true, "files.watcherExclude": { diff --git a/embassy-extras/src/fmt.rs b/embassy-extras/src/fmt.rs index 2646c57a..06697081 100644 --- a/embassy-extras/src/fmt.rs +++ b/embassy-extras/src/fmt.rs @@ -104,56 +104,66 @@ macro_rules! panic { } macro_rules! trace { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::trace!($($x)*); + ::log::trace!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::trace!($($x)*); + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! debug { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(fevature = "log")] - ::log::debug!($($x)*); + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::debug!($($x)*); + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! info { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::info!($($x)*); + ::log::info!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::info!($($x)*); + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! warn { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::warn!($($x)*); + ::log::warn!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::warn!($($x)*); + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! error { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::error!($($x)*); + ::log::error!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::error!($($x)*); + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } diff --git a/embassy-net/src/fmt.rs b/embassy-net/src/fmt.rs index 2646c57a..06697081 100644 --- a/embassy-net/src/fmt.rs +++ b/embassy-net/src/fmt.rs @@ -104,56 +104,66 @@ macro_rules! panic { } macro_rules! trace { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::trace!($($x)*); + ::log::trace!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::trace!($($x)*); + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! debug { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(fevature = "log")] - ::log::debug!($($x)*); + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::debug!($($x)*); + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! info { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::info!($($x)*); + ::log::info!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::info!($($x)*); + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! warn { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::warn!($($x)*); + ::log::warn!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::warn!($($x)*); + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! error { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::error!($($x)*); + ::log::error!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::error!($($x)*); + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } diff --git a/embassy-nrf/src/fmt.rs b/embassy-nrf/src/fmt.rs index 2646c57a..06697081 100644 --- a/embassy-nrf/src/fmt.rs +++ b/embassy-nrf/src/fmt.rs @@ -104,56 +104,66 @@ macro_rules! panic { } macro_rules! trace { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::trace!($($x)*); + ::log::trace!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::trace!($($x)*); + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! debug { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(fevature = "log")] - ::log::debug!($($x)*); + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::debug!($($x)*); + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! info { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::info!($($x)*); + ::log::info!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::info!($($x)*); + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! warn { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::warn!($($x)*); + ::log::warn!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::warn!($($x)*); + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! error { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::error!($($x)*); + ::log::error!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::error!($($x)*); + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } diff --git a/embassy-rp/src/fmt.rs b/embassy-rp/src/fmt.rs index 2646c57a..06697081 100644 --- a/embassy-rp/src/fmt.rs +++ b/embassy-rp/src/fmt.rs @@ -104,56 +104,66 @@ macro_rules! panic { } macro_rules! trace { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::trace!($($x)*); + ::log::trace!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::trace!($($x)*); + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! debug { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(fevature = "log")] - ::log::debug!($($x)*); + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::debug!($($x)*); + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! info { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::info!($($x)*); + ::log::info!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::info!($($x)*); + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! warn { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::warn!($($x)*); + ::log::warn!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::warn!($($x)*); + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! error { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::error!($($x)*); + ::log::error!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::error!($($x)*); + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } diff --git a/embassy-stm32/src/fmt.rs b/embassy-stm32/src/fmt.rs index 2646c57a..06697081 100644 --- a/embassy-stm32/src/fmt.rs +++ b/embassy-stm32/src/fmt.rs @@ -104,56 +104,66 @@ macro_rules! panic { } macro_rules! trace { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::trace!($($x)*); + ::log::trace!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::trace!($($x)*); + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! debug { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(fevature = "log")] - ::log::debug!($($x)*); + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::debug!($($x)*); + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! info { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::info!($($x)*); + ::log::info!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::info!($($x)*); + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! warn { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::warn!($($x)*); + ::log::warn!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::warn!($($x)*); + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! error { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::error!($($x)*); + ::log::error!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::error!($($x)*); + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } diff --git a/embassy/src/fmt.rs b/embassy/src/fmt.rs index 2646c57a..06697081 100644 --- a/embassy/src/fmt.rs +++ b/embassy/src/fmt.rs @@ -104,56 +104,66 @@ macro_rules! panic { } macro_rules! trace { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::trace!($($x)*); + ::log::trace!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::trace!($($x)*); + ::defmt::trace!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! debug { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { - #[cfg(fevature = "log")] - ::log::debug!($($x)*); + #[cfg(feature = "log")] + ::log::debug!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::debug!($($x)*); + ::defmt::debug!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! info { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::info!($($x)*); + ::log::info!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::info!($($x)*); + ::defmt::info!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! warn { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::warn!($($x)*); + ::log::warn!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::warn!($($x)*); + ::defmt::warn!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } macro_rules! error { - ($($x:tt)*) => { + ($s:literal $(, $x:expr)* $(,)?) => { { #[cfg(feature = "log")] - ::log::error!($($x)*); + ::log::error!($s $(, $x)*); #[cfg(feature = "defmt")] - ::defmt::error!($($x)*); + ::defmt::error!($s $(, $x)*); + #[cfg(not(any(feature = "log", feature="defmt")))] + let _ = ($( & $x ),*); } }; } diff --git a/stm32-metapac/Cargo.toml b/stm32-metapac/Cargo.toml index c92c5f00..971d7695 100644 --- a/stm32-metapac/Cargo.toml +++ b/stm32-metapac/Cargo.toml @@ -9,16 +9,18 @@ resolver = "2" cortex-m = "0.7.2" cortex-m-rt = { version = "0.6.8", optional = true } +# BEGIN BUILD DEPENDENCIES +# These are removed when generating the pre-generated crate using the tool at gen/. [build-dependencies] regex = "1.4.6" chiptool = { git = "https://github.com/embassy-rs/chiptool", rev = "86b77165078065058098e981d49d2dd213b2feba" } serde = { version = "1.0.123", features = [ "derive" ]} serde_yaml = "0.8.15" +# END BUILD DEPENDENCIES [features] rt = ["cortex-m-rt/device"] - # BEGIN GENERATED FEATURES # Generated by gen_features.py. DO NOT EDIT. stm32f030c6 = []