Skip to content

Commit 361ee07

Browse files
committed
Emit an error in macro runtime_pattern if crate feature is not enabled
1 parent 5e20c0e commit 361ee07

File tree

4 files changed

+31
-0
lines changed

4 files changed

+31
-0
lines changed

spdlog/src/formatter/pattern_formatter/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,21 @@ use crate::{
342342
/// [`FullFormatter`]: crate::formatter::FullFormatter
343343
pub use ::spdlog_macros::pattern;
344344

345+
// Emit a compile error if the feature is not enabled.
346+
#[cfg(not(feature = "runtime-pattern"))]
347+
pub use crate::__runtime_pattern_disabled as runtime_pattern;
348+
349+
#[cfg(not(feature = "runtime-pattern"))]
350+
#[doc(hidden)]
351+
#[macro_export]
352+
macro_rules! __runtime_pattern_disabled {
353+
($($_:tt)*) => {
354+
compile_error!(
355+
"macro `runtime_pattern` required to enable crate feature `runtime-pattern` for spdlog-rs"
356+
);
357+
};
358+
}
359+
345360
/// Formats logs according to a specified pattern.
346361
#[derive(Clone)]
347362
pub struct PatternFormatter<P> {

spdlog/tests/compile_fail.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ fn compile_fail() {
55
t.compile_fail("tests/compile_fail/pattern_macro_*.rs");
66
#[cfg(feature = "runtime-pattern")]
77
t.compile_fail("tests/compile_fail/pattern_runtime_macro_*.rs");
8+
#[cfg(not(feature = "runtime-pattern"))]
9+
t.compile_fail("tests/compile_fail/pattern_runtime_disabled.rs");
810
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use spdlog::formatter::runtime_pattern;
2+
3+
fn runtime_pattern() {
4+
runtime_pattern!("{logger}");
5+
}
6+
7+
fn main() {}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
error: macro `runtime_pattern` required to enable crate feature `runtime-pattern` for spdlog-rs
2+
--> tests/compile_fail/pattern_runtime_disabled.rs:4:5
3+
|
4+
4 | runtime_pattern!("{logger}");
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
= note: this error originates in the macro `runtime_pattern` (in Nightly builds, run with -Z macro-backtrace for more info)

0 commit comments

Comments
 (0)