about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2022-04-26 15:16:23 -0700
committerDavid Tolnay <dtolnay@gmail.com>2022-05-22 16:11:08 -0700
commit0502496b1e5c53fe0f5c7e9a6bb67c7cc6777d33 (patch)
treecc76996e82c5563d4609f63c622ef042261982de
parentae29890ab6a572fca53f693cccdf6654dd07f7d5 (diff)
downloadrust-0502496b1e5c53fe0f5c7e9a6bb67c7cc6777d33.tar.gz
rust-0502496b1e5c53fe0f5c7e9a6bb67c7cc6777d33.zip
Make write/print macros eagerly drop temporaries
-rw-r--r--library/core/src/macros/mod.rs14
-rw-r--r--library/std/src/macros.rs12
2 files changed, 14 insertions, 12 deletions
diff --git a/library/core/src/macros/mod.rs b/library/core/src/macros/mod.rs
index a231f533d19..dbc3d2923ed 100644
--- a/library/core/src/macros/mod.rs
+++ b/library/core/src/macros/mod.rs
@@ -496,9 +496,10 @@ macro_rules! r#try {
 #[stable(feature = "rust1", since = "1.0.0")]
 #[cfg_attr(not(test), rustc_diagnostic_item = "write_macro")]
 macro_rules! write {
-    ($dst:expr, $($arg:tt)*) => {
-        $dst.write_fmt($crate::format_args!($($arg)*))
-    };
+    ($dst:expr, $($arg:tt)*) => {{
+        let result = $dst.write_fmt($crate::format_args!($($arg)*));
+        result
+    }};
 }
 
 /// Write formatted data into a buffer, with a newline appended.
@@ -553,9 +554,10 @@ macro_rules! writeln {
     ($dst:expr $(,)?) => {
         $crate::write!($dst, "\n")
     };
-    ($dst:expr, $($arg:tt)*) => {
-        $dst.write_fmt($crate::format_args_nl!($($arg)*))
-    };
+    ($dst:expr, $($arg:tt)*) => {{
+        let result = $dst.write_fmt($crate::format_args_nl!($($arg)*));
+        result
+    }};
 }
 
 /// Indicates unreachable code.
diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs
index c7348951511..0cb21ef53b1 100644
--- a/library/std/src/macros.rs
+++ b/library/std/src/macros.rs
@@ -62,9 +62,9 @@ macro_rules! panic {
 #[cfg_attr(not(test), rustc_diagnostic_item = "print_macro")]
 #[allow_internal_unstable(print_internals)]
 macro_rules! print {
-    ($($arg:tt)*) => {
-        $crate::io::_print($crate::format_args!($($arg)*))
-    };
+    ($($arg:tt)*) => {{
+        $crate::io::_print($crate::format_args!($($arg)*));
+    }};
 }
 
 /// Prints to the standard output, with a newline.
@@ -133,9 +133,9 @@ macro_rules! println {
 #[cfg_attr(not(test), rustc_diagnostic_item = "eprint_macro")]
 #[allow_internal_unstable(print_internals)]
 macro_rules! eprint {
-    ($($arg:tt)*) => {
-        $crate::io::_eprint($crate::format_args!($($arg)*))
-    };
+    ($($arg:tt)*) => {{
+        $crate::io::_eprint($crate::format_args!($($arg)*));
+    }};
 }
 
 /// Prints to the standard error, with a newline.