Make write/print macros eagerly drop temporaries

This commit is contained in:
David Tolnay 2022-04-26 15:16:23 -07:00
parent ae29890ab6
commit 0502496b1e
No known key found for this signature in database
GPG key ID: F9BA143B95FF6D82
2 changed files with 14 additions and 12 deletions

View file

@ -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.