Skip to content

Commit aaf6cc3

Browse files
committed
Prevent leakage of fmt! into the compiler
We're not outright removing fmt! just yet, but this prevents it from leaking into the compiler further (it's still turned on by default for all other code).
1 parent 1dbc467 commit aaf6cc3

File tree

3 files changed

+63
-50
lines changed

3 files changed

+63
-50
lines changed

Makefile.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ ifneq ($(wildcard $(NON_BUILD_TARGET_TRIPLES)),)
8888
CFG_INFO := $(info cfg: non-build target triples $(NON_BUILD_TARGET_TRIPLES))
8989
endif
9090

91-
CFG_RUSTC_FLAGS := $(RUSTFLAGS)
91+
CFG_RUSTC_FLAGS := $(RUSTFLAGS) --cfg nofmt
9292
CFG_GCCISH_CFLAGS :=
9393
CFG_GCCISH_LINK_FLAGS :=
9494

src/libsyntax/ext/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub fn syntax_expander_table() -> SyntaxEnv {
222222
span: None,
223223
} as @SyntaxExpanderTTItemTrait,
224224
None)));
225-
syntax_expanders.insert(intern(&"fmt"),
225+
syntax_expanders.insert(intern(&"oldfmt"),
226226
builtin_normal_tt_no_ctxt(
227227
ext::fmt::expand_syntax_ext));
228228
syntax_expanders.insert(intern(&"format_args"),

src/libsyntax/ext/expand.rs

Lines changed: 61 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -809,30 +809,49 @@ pub fn std_macros() -> @str {
809809

810810
macro_rules! ignore (($($x:tt)*) => (()))
811811

812-
macro_rules! log(
813-
($lvl:expr, $arg:expr) => ({
814-
let lvl = $lvl;
815-
if lvl <= __log_level() {
816-
format_args!(|args| {
817-
::std::logging::log(lvl, args)
818-
}, \"{}\", fmt!(\"%?\", $arg))
819-
}
820-
});
821-
($lvl:expr, $($arg:expr),+) => ({
822-
let lvl = $lvl;
823-
if lvl <= __log_level() {
824-
format_args!(|args| {
825-
::std::logging::log(lvl, args)
826-
}, \"{}\", fmt!($($arg),+))
827-
}
828-
})
829-
)
830-
macro_rules! error( ($($arg:tt)*) => (log!(1u32, $($arg)*)) )
831-
macro_rules! warn ( ($($arg:tt)*) => (log!(2u32, $($arg)*)) )
832-
macro_rules! info ( ($($arg:tt)*) => (log!(3u32, $($arg)*)) )
833-
macro_rules! debug( ($($arg:tt)*) => (
834-
if cfg!(not(ndebug)) { log!(4u32, $($arg)*) }
835-
))
812+
#[cfg(not(nofmt))]
813+
mod fmt_extension {
814+
#[macro_escape];
815+
816+
macro_rules! fmt(($($arg:tt)*) => (oldfmt!($($arg)*)))
817+
818+
macro_rules! log(
819+
($lvl:expr, $arg:expr) => ({
820+
let lvl = $lvl;
821+
if lvl <= __log_level() {
822+
format_args!(|args| {
823+
::std::logging::log(lvl, args)
824+
}, \"{}\", fmt!(\"%?\", $arg))
825+
}
826+
});
827+
($lvl:expr, $($arg:expr),+) => ({
828+
let lvl = $lvl;
829+
if lvl <= __log_level() {
830+
format_args!(|args| {
831+
::std::logging::log(lvl, args)
832+
}, \"{}\", fmt!($($arg),+))
833+
}
834+
})
835+
)
836+
macro_rules! error( ($($arg:tt)*) => (log!(1u32, $($arg)*)) )
837+
macro_rules! warn ( ($($arg:tt)*) => (log!(2u32, $($arg)*)) )
838+
macro_rules! info ( ($($arg:tt)*) => (log!(3u32, $($arg)*)) )
839+
macro_rules! debug( ($($arg:tt)*) => (
840+
if cfg!(not(ndebug)) { log!(4u32, $($arg)*) }
841+
))
842+
843+
macro_rules! fail(
844+
() => (
845+
fail!(\"explicit failure\")
846+
);
847+
($msg:expr) => (
848+
::std::sys::FailWithCause::fail_with($msg, file!(), line!())
849+
);
850+
($( $arg:expr ),+) => (
851+
::std::sys::FailWithCause::fail_with(fmt!( $($arg),+ ), file!(), line!())
852+
)
853+
)
854+
}
836855

837856
macro_rules! log2(
838857
($lvl:expr, $($arg:tt)+) => ({
@@ -851,24 +870,15 @@ pub fn std_macros() -> @str {
851870
if cfg!(not(ndebug)) { log2!(4u32, $($arg)*) }
852871
))
853872

854-
macro_rules! fail(
855-
() => (
856-
fail!(\"explicit failure\")
857-
);
858-
($msg:expr) => (
859-
::std::sys::FailWithCause::fail_with($msg, file!(), line!())
860-
);
861-
($( $arg:expr ),+) => (
862-
::std::sys::FailWithCause::fail_with(fmt!( $($arg),+ ), file!(), line!())
863-
)
864-
)
865-
866873
macro_rules! fail2(
867874
() => (
868-
fail!(\"explicit failure\")
875+
fail2!(\"explicit failure\")
876+
);
877+
($fmt:expr) => (
878+
::std::sys::FailWithCause::fail_with($fmt, file!(), line!())
869879
);
870-
($($arg:tt)*) => (
871-
::std::sys::FailWithCause::fail_with(format!($($arg)*), file!(), line!())
880+
($fmt:expr, $($arg:tt)*) => (
881+
::std::sys::FailWithCause::fail_with(format!($fmt, $($arg)*), file!(), line!())
872882
)
873883
)
874884

@@ -894,12 +904,14 @@ pub fn std_macros() -> @str {
894904
macro_rules! assert_eq (
895905
($given:expr , $expected:expr) => (
896906
{
897-
let given_val = $given;
898-
let expected_val = $expected;
907+
let given_val = &($given);
908+
let expected_val = &($expected);
899909
// check both directions of equality....
900-
if !((given_val == expected_val) && (expected_val == given_val)) {
901-
fail!(\"assertion failed: `(left == right) && (right == \
902-
left)` (left: `%?`, right: `%?`)\", given_val, expected_val);
910+
if !((*given_val == *expected_val) &&
911+
(*expected_val == *given_val)) {
912+
fail2!(\"assertion failed: `(left == right) && (right == \
913+
left)` (left: `{:?}`, right: `{:?}`)\",
914+
*given_val, *expected_val);
903915
}
904916
}
905917
)
@@ -917,8 +929,8 @@ pub fn std_macros() -> @str {
917929
given_val.approx_eq(&expected_val) &&
918930
expected_val.approx_eq(&given_val)
919931
) {
920-
fail!(\"left: %? does not approximately equal right: %?\",
921-
given_val, expected_val);
932+
fail2!(\"left: {:?} does not approximately equal right: {:?}\",
933+
given_val, expected_val);
922934
}
923935
}
924936
);
@@ -934,7 +946,8 @@ pub fn std_macros() -> @str {
934946
given_val.approx_eq_eps(&expected_val, &epsilon_val) &&
935947
expected_val.approx_eq_eps(&given_val, &epsilon_val)
936948
) {
937-
fail!(\"left: %? does not approximately equal right: %? with epsilon: %?\",
949+
fail2!(\"left: {:?} does not approximately equal right: \
950+
{:?} with epsilon: {:?}\",
938951
given_val, expected_val, epsilon_val);
939952
}
940953
}
@@ -968,7 +981,7 @@ pub fn std_macros() -> @str {
968981
969982
*/
970983
macro_rules! unreachable (() => (
971-
fail!(\"internal error: entered unreachable code\");
984+
fail2!(\"internal error: entered unreachable code\");
972985
))
973986

974987
macro_rules! condition (

0 commit comments

Comments
 (0)