fmt: Add dunmy use to avoid "unused variable" errors when no log is enabled.

This commit is contained in:
Dario Nieuwenhuis 2021-06-07 03:21:09 +02:00
parent ef1ebefec0
commit 3be49d3e79
8 changed files with 161 additions and 99 deletions

View file

@ -3,8 +3,8 @@
"editor.formatOnSave": true, "editor.formatOnSave": true,
"rust-analyzer.checkOnSave.allFeatures": false, "rust-analyzer.checkOnSave.allFeatures": false,
"rust-analyzer.checkOnSave.allTargets": false, "rust-analyzer.checkOnSave.allTargets": false,
//"rust-analyzer.cargo.target": "thumbv7em-none-eabi", "rust-analyzer.cargo.target": "thumbv7em-none-eabi",
//"rust-analyzer.checkOnSave.target": "thumbv7em-none-eabi", "rust-analyzer.checkOnSave.target": "thumbv7em-none-eabi",
"rust-analyzer.procMacro.enable": true, "rust-analyzer.procMacro.enable": true,
"rust-analyzer.cargo.loadOutDirsFromCheck": true, "rust-analyzer.cargo.loadOutDirsFromCheck": true,
"files.watcherExclude": { "files.watcherExclude": {

View file

@ -104,56 +104,66 @@ macro_rules! panic {
} }
macro_rules! trace { macro_rules! trace {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::trace!($($x)*); ::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::trace!($($x)*); ::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! debug { macro_rules! debug {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(fevature = "log")] #[cfg(feature = "log")]
::log::debug!($($x)*); ::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::debug!($($x)*); ::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! info { macro_rules! info {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::info!($($x)*); ::log::info!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::info!($($x)*); ::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! warn { macro_rules! warn {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::warn!($($x)*); ::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::warn!($($x)*); ::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! error { macro_rules! error {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::error!($($x)*); ::log::error!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::error!($($x)*); ::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }

View file

@ -104,56 +104,66 @@ macro_rules! panic {
} }
macro_rules! trace { macro_rules! trace {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::trace!($($x)*); ::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::trace!($($x)*); ::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! debug { macro_rules! debug {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(fevature = "log")] #[cfg(feature = "log")]
::log::debug!($($x)*); ::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::debug!($($x)*); ::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! info { macro_rules! info {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::info!($($x)*); ::log::info!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::info!($($x)*); ::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! warn { macro_rules! warn {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::warn!($($x)*); ::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::warn!($($x)*); ::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! error { macro_rules! error {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::error!($($x)*); ::log::error!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::error!($($x)*); ::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }

View file

@ -104,56 +104,66 @@ macro_rules! panic {
} }
macro_rules! trace { macro_rules! trace {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::trace!($($x)*); ::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::trace!($($x)*); ::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! debug { macro_rules! debug {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(fevature = "log")] #[cfg(feature = "log")]
::log::debug!($($x)*); ::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::debug!($($x)*); ::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! info { macro_rules! info {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::info!($($x)*); ::log::info!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::info!($($x)*); ::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! warn { macro_rules! warn {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::warn!($($x)*); ::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::warn!($($x)*); ::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! error { macro_rules! error {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::error!($($x)*); ::log::error!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::error!($($x)*); ::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }

View file

@ -104,56 +104,66 @@ macro_rules! panic {
} }
macro_rules! trace { macro_rules! trace {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::trace!($($x)*); ::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::trace!($($x)*); ::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! debug { macro_rules! debug {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(fevature = "log")] #[cfg(feature = "log")]
::log::debug!($($x)*); ::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::debug!($($x)*); ::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! info { macro_rules! info {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::info!($($x)*); ::log::info!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::info!($($x)*); ::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! warn { macro_rules! warn {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::warn!($($x)*); ::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::warn!($($x)*); ::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! error { macro_rules! error {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::error!($($x)*); ::log::error!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::error!($($x)*); ::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }

View file

@ -104,56 +104,66 @@ macro_rules! panic {
} }
macro_rules! trace { macro_rules! trace {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::trace!($($x)*); ::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::trace!($($x)*); ::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! debug { macro_rules! debug {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(fevature = "log")] #[cfg(feature = "log")]
::log::debug!($($x)*); ::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::debug!($($x)*); ::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! info { macro_rules! info {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::info!($($x)*); ::log::info!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::info!($($x)*); ::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! warn { macro_rules! warn {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::warn!($($x)*); ::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::warn!($($x)*); ::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! error { macro_rules! error {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::error!($($x)*); ::log::error!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::error!($($x)*); ::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }

View file

@ -104,56 +104,66 @@ macro_rules! panic {
} }
macro_rules! trace { macro_rules! trace {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::trace!($($x)*); ::log::trace!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::trace!($($x)*); ::defmt::trace!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! debug { macro_rules! debug {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(fevature = "log")] #[cfg(feature = "log")]
::log::debug!($($x)*); ::log::debug!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::debug!($($x)*); ::defmt::debug!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! info { macro_rules! info {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::info!($($x)*); ::log::info!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::info!($($x)*); ::defmt::info!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! warn { macro_rules! warn {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::warn!($($x)*); ::log::warn!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::warn!($($x)*); ::defmt::warn!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }
macro_rules! error { macro_rules! error {
($($x:tt)*) => { ($s:literal $(, $x:expr)* $(,)?) => {
{ {
#[cfg(feature = "log")] #[cfg(feature = "log")]
::log::error!($($x)*); ::log::error!($s $(, $x)*);
#[cfg(feature = "defmt")] #[cfg(feature = "defmt")]
::defmt::error!($($x)*); ::defmt::error!($s $(, $x)*);
#[cfg(not(any(feature = "log", feature="defmt")))]
let _ = ($( & $x ),*);
} }
}; };
} }

View file

@ -9,16 +9,18 @@ resolver = "2"
cortex-m = "0.7.2" cortex-m = "0.7.2"
cortex-m-rt = { version = "0.6.8", optional = true } 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] [build-dependencies]
regex = "1.4.6" regex = "1.4.6"
chiptool = { git = "https://github.com/embassy-rs/chiptool", rev = "86b77165078065058098e981d49d2dd213b2feba" } chiptool = { git = "https://github.com/embassy-rs/chiptool", rev = "86b77165078065058098e981d49d2dd213b2feba" }
serde = { version = "1.0.123", features = [ "derive" ]} serde = { version = "1.0.123", features = [ "derive" ]}
serde_yaml = "0.8.15" serde_yaml = "0.8.15"
# END BUILD DEPENDENCIES
[features] [features]
rt = ["cortex-m-rt/device"] rt = ["cortex-m-rt/device"]
# BEGIN GENERATED FEATURES # BEGIN GENERATED FEATURES
# Generated by gen_features.py. DO NOT EDIT. # Generated by gen_features.py. DO NOT EDIT.
stm32f030c6 = [] stm32f030c6 = []