Skip to content

Commit eaed16c

Browse files
committed
auto merge of #5278 : brson/rust/logplusplus, r=brson
r? `log` can polymorphically log anything, but debug!, etc. requires a format string. With this patch you can equivalently write `debug!(foo)` or `debug!("%?", foo)`. I'm doing this because I was trying to remove `log` (replacing it with nothing, at least temporarily), but there are a number of logging statements that just want to print an arbitrary value and don't care about the format string. I'm not entirely convinced this is a good change, since it overloads the implementation of these macros and makes their usage slightly more nuanced.
2 parents ac3dc66 + dd4d450 commit eaed16c

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

src/libsyntax/ext/expand.rs

+32-8
Original file line numberDiff line numberDiff line change
@@ -409,14 +409,38 @@ pub fn core_macros() -> ~str {
409409
~"pub mod macros {
410410
macro_rules! ignore (($($x:tt)*) => (()))
411411

412-
macro_rules! error ( ($( $arg:expr ),+) => (
413-
log(::core::error, fmt!( $($arg),+ )) ))
414-
macro_rules! warn ( ($( $arg:expr ),+) => (
415-
log(::core::warn, fmt!( $($arg),+ )) ))
416-
macro_rules! info ( ($( $arg:expr ),+) => (
417-
log(::core::info, fmt!( $($arg),+ )) ))
418-
macro_rules! debug ( ($( $arg:expr ),+) => (
419-
log(::core::debug, fmt!( $($arg),+ )) ))
412+
macro_rules! error (
413+
($arg:expr) => (
414+
log(::core::error, fmt!( \"%?\", $arg ))
415+
);
416+
($( $arg:expr ),+) => (
417+
log(::core::error, fmt!( $($arg),+ ))
418+
)
419+
)
420+
macro_rules! warn (
421+
($arg:expr) => (
422+
log(::core::warn, fmt!( \"%?\", $arg ))
423+
);
424+
($( $arg:expr ),+) => (
425+
log(::core::warn, fmt!( $($arg),+ ))
426+
)
427+
)
428+
macro_rules! info (
429+
($arg:expr) => (
430+
log(::core::info, fmt!( \"%?\", $arg ))
431+
);
432+
($( $arg:expr ),+) => (
433+
log(::core::info, fmt!( $($arg),+ ))
434+
)
435+
)
436+
macro_rules! debug (
437+
($arg:expr) => (
438+
log(::core::debug, fmt!( \"%?\", $arg ))
439+
);
440+
($( $arg:expr ),+) => (
441+
log(::core::debug, fmt!( $($arg),+ ))
442+
)
443+
)
420444

421445
macro_rules! fail(
422446
($msg: expr) => (

src/test/run-pass/log-poly.rs

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
enum Numbers {
2+
Three
3+
}
4+
5+
fn main() {
6+
debug!(1);
7+
info!(2.0);
8+
warn!(Three);
9+
error!(~[4]);
10+
}

0 commit comments

Comments
 (0)