Skip to content

Commit 3a8f81a

Browse files
committed
Make [e]println macros eagerly drop temporaries (for backport)
1 parent 69a5d24 commit 3a8f81a

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

library/std/src/macros.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ macro_rules! println {
9999
() => {
100100
$crate::print!("\n")
101101
};
102-
($($arg:tt)*) => {
103-
$crate::io::_print($crate::format_args_nl!($($arg)*))
104-
};
102+
($($arg:tt)*) => {{
103+
$crate::io::_print($crate::format_args_nl!($($arg)*));
104+
}};
105105
}
106106

107107
/// Prints to the standard error.
@@ -164,9 +164,9 @@ macro_rules! eprintln {
164164
() => {
165165
$crate::eprint!("\n")
166166
};
167-
($($arg:tt)*) => {
168-
$crate::io::_eprint($crate::format_args_nl!($($arg)*))
169-
};
167+
($($arg:tt)*) => {{
168+
$crate::io::_eprint($crate::format_args_nl!($($arg)*));
169+
}};
170170
}
171171

172172
/// Prints and returns the value of a given expression for quick and dirty

src/test/pretty/dollar-crate.pp

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
// pp-exact:dollar-crate.pp
1010

1111
fn main() {
12-
::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[]));
12+
{ ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[])); };
1313
}

src/test/ui/macros/trace-macro.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ LL | println!("Hello, World!");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: expanding `println! { "Hello, World!" }`
8-
= note: to `$crate :: io :: _print($crate :: format_args_nl! ("Hello, World!"))`
8+
= note: to `{ $crate :: io :: _print($crate :: format_args_nl! ("Hello, World!")) ; }`
99

src/test/ui/pattern/usefulness/tuple-struct-nonexhaustive.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ LL | struct Foo(isize, isize);
1212
= note: the matched value is of type `Foo`
1313
help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown
1414
|
15-
LL ~ Foo(2, b) => println!("{}", b),
15+
LL ~ Foo(2, b) => println!("{}", b)
1616
LL + Foo(_, _) => todo!()
1717
|
1818

0 commit comments

Comments
 (0)