Skip to content

Commit a3e39b9

Browse files
committed
Introduce alternate forms of logging
These new macros are all based on format! instead of fmt! and purely exist for bootstrapping purposes. After the next snapshot, all uses of logging will be migrated to these macros, and then after the next snapshot after that we can drop the `2` suffix on everything
1 parent eb836dd commit a3e39b9

File tree

2 files changed

+31
-24
lines changed

2 files changed

+31
-24
lines changed

src/libsyntax/ext/expand.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -758,32 +758,32 @@ pub fn std_macros() -> @str {
758758
)
759759
)
760760

761-
// conditionally define debug!, but keep it type checking even
762-
// in non-debug builds.
763-
macro_rules! __debug (
761+
macro_rules! debug (
764762
($arg:expr) => (
765-
__log(4u32, fmt!( \"%?\", $arg ))
763+
if cfg!(debug) { __log(4u32, fmt!( \"%?\", $arg )) }
766764
);
767765
($( $arg:expr ),+) => (
768-
__log(4u32, fmt!( $($arg),+ ))
766+
if cfg!(debug) { __log(4u32, fmt!( $($arg),+ )) }
769767
)
770768
)
771769

772-
#[cfg(debug)]
773-
#[macro_escape]
774-
mod debug_macro {
775-
macro_rules! debug (($($arg:expr),*) => {
776-
__debug!($($arg),*)
777-
})
778-
}
770+
macro_rules! error2 (
771+
($($arg:tt)*) => ( __log(1u32, format!($($arg)*)))
772+
)
779773

780-
#[cfg(not(debug))]
781-
#[macro_escape]
782-
mod debug_macro {
783-
macro_rules! debug (($($arg:expr),*) => {
784-
if false { __debug!($($arg),*) }
785-
})
786-
}
774+
macro_rules! warn2 (
775+
($($arg:tt)*) => ( __log(2u32, format!($($arg)*)))
776+
)
777+
778+
macro_rules! info2 (
779+
($($arg:tt)*) => ( __log(3u32, format!($($arg)*)))
780+
)
781+
782+
macro_rules! debug2 (
783+
($($arg:tt)*) => (
784+
if cfg!(debug) { __log(4u32, format!($($arg)*)) }
785+
)
786+
)
787787

788788
macro_rules! fail(
789789
() => (
@@ -797,6 +797,15 @@ pub fn std_macros() -> @str {
797797
)
798798
)
799799

800+
macro_rules! fail2(
801+
() => (
802+
fail!(\"explicit failure\")
803+
);
804+
($($arg:tt)+) => (
805+
::std::sys::FailWithCause::fail_with(format!($($arg)+), file!(), line!())
806+
)
807+
)
808+
800809
macro_rules! assert(
801810
($cond:expr) => {
802811
if !$cond {
@@ -964,15 +973,13 @@ pub fn std_macros() -> @str {
964973
// allocation but should rather delegate to an invocation of
965974
// write! instead of format!
966975
macro_rules! print (
967-
() => ();
968-
($arg:expr) => ( ::std::io::print(format!(\"{}\", $arg)));
969-
($fmt:expr, $($arg:tt)+) => ( ::std::io::print(format!($fmt, $($arg)+)))
976+
($($arg:tt)+) => ( ::std::io::print(format!($($arg)+)))
970977
)
971978

972979
// FIXME(#6846) once stdio is redesigned, this shouldn't perform an
973980
// allocation but should rather delegate to an io::Writer
974981
macro_rules! println (
975-
($($arg:tt)*) => ({ print!($($arg)*); ::std::io::println(\"\"); })
982+
($($arg:tt)+) => ({ print!($($arg)+); ::std::io::println(\"\"); })
976983
)
977984

978985
// NOTE: use this after a snapshot lands to abstract the details

src/test/run-pass/ifmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ fn test_write() {
240240
// Just make sure that the macros are defined, there's not really a lot that we
241241
// can do with them just yet (to test the output)
242242
fn test_print() {
243-
print!(1);
243+
print!("hi");
244244
print!("{:?}", ~[0u8]);
245245
println!("hello");
246246
println!("this is a {}", "test");

0 commit comments

Comments
 (0)