Skip to content

Commit 9916b52

Browse files
committed
Add compile_error! for mutually exclusive features
defmt feature is incompatible with log and std. In mctp-estack, move the compile_error prior to 'mod' items. Otherwise it prints warnings in every module. Signed-off-by: Matt Johnston <matt@codeconstruct.com.au>
1 parent ecbcf96 commit 9916b52

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

mctp-estack/src/lib.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ use heapless::FnvIndexMap;
4545

4646
use mctp::{Eid, Error, MsgIC, MsgType, Result, Tag, TagValue};
4747

48+
#[cfg(not(any(feature = "log", feature = "defmt")))]
49+
compile_error!("Either log or defmt feature must be enabled");
50+
#[cfg(all(feature = "log", feature = "defmt"))]
51+
compile_error!("log and defmt features are mutually exclusive");
52+
4853
pub mod control;
4954
pub mod fragment;
5055
pub mod i2c;
@@ -733,9 +738,6 @@ impl EventStamp {
733738
}
734739
}
735740

736-
#[cfg(not(any(feature = "log", feature = "defmt")))]
737-
compile_error!("Either log or defmt feature must be enabled");
738-
739741
pub(crate) mod fmt {
740742
#[cfg(feature = "defmt")]
741743
pub use defmt::{debug, error, info, trace, warn};

mctp-usb-embassy/src/mctpusb.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ use log::{debug, error, info, trace, warn};
1212

1313
#[cfg(not(any(feature = "log", feature = "defmt")))]
1414
compile_error!("Either log or defmt feature must be enabled");
15+
#[cfg(all(feature = "log", feature = "defmt"))]
16+
compile_error!("log and defmt features are mutually exclusive");
1517

1618
use core::ops::Range;
1719

mctp/src/lib.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,11 @@
1818
1919
use core::future::Future;
2020

21+
// Currently there is no defmt::Format implementation for std::io::Error
22+
// (can't be derived). If needed that could be manually implemented.
23+
#[cfg(all(feature = "std", feature = "defmt"))]
24+
compile_error!("std and defmt features are currently mutually exclusive");
25+
2126
/// MCTP endpoint ID
2227
#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
2328
#[cfg_attr(feature = "defmt", derive(defmt::Format))]

0 commit comments

Comments
 (0)