Skip to content

Commit 0502496

Browse files
committed
Make write/print macros eagerly drop temporaries
1 parent ae29890 commit 0502496

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

library/core/src/macros/mod.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -496,9 +496,10 @@ macro_rules! r#try {
496496
#[stable(feature = "rust1", since = "1.0.0")]
497497
#[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")]
498498
macro_rules! write {
499-
($dst:expr, $($arg:tt)*) => {
500-
$dst.write_fmt($crate::format_args!($($arg)*))
501-
};
499+
($dst:expr, $($arg:tt)*) => {{
500+
let result = $dst.write_fmt($crate::format_args!($($arg)*));
501+
result
502+
}};
502503
}
503504

504505
/// Write formatted data into a buffer, with a newline appended.
@@ -553,9 +554,10 @@ macro_rules! writeln {
553554
($dst:expr $(,)?) => {
554555
$crate::write!($dst, "\n")
555556
};
556-
($dst:expr, $($arg:tt)*) => {
557-
$dst.write_fmt($crate::format_args_nl!($($arg)*))
558-
};
557+
($dst:expr, $($arg:tt)*) => {{
558+
let result = $dst.write_fmt($crate::format_args_nl!($($arg)*));
559+
result
560+
}};
559561
}
560562

561563
/// Indicates unreachable code.

library/std/src/macros.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ macro_rules! panic {
6262
#[cfg_attr(not(test), rustc_diagnostic_item = "print_macro")]
6363
#[allow_internal_unstable(print_internals)]
6464
macro_rules! print {
65-
($($arg:tt)*) => {
66-
$crate::io::_print($crate::format_args!($($arg)*))
67-
};
65+
($($arg:tt)*) => {{
66+
$crate::io::_print($crate::format_args!($($arg)*));
67+
}};
6868
}
6969

7070
/// Prints to the standard output, with a newline.
@@ -133,9 +133,9 @@ macro_rules! println {
133133
#[cfg_attr(not(test), rustc_diagnostic_item = "eprint_macro")]
134134
#[allow_internal_unstable(print_internals)]
135135
macro_rules! eprint {
136-
($($arg:tt)*) => {
137-
$crate::io::_eprint($crate::format_args!($($arg)*))
138-
};
136+
($($arg:tt)*) => {{
137+
$crate::io::_eprint($crate::format_args!($($arg)*));
138+
}};
139139
}
140140

141141
/// Prints to the standard error, with a newline.

0 commit comments

Comments
 (0)