From 3a8f81aac94ccb4051410232e4f39b89ed6dae4e Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Tue, 26 Apr 2022 15:16:23 -0700 Subject: [PATCH 1/2] Make [e]println macros eagerly drop temporaries (for backport) --- library/std/src/macros.rs | 12 ++++++------ src/test/pretty/dollar-crate.pp | 2 +- src/test/ui/macros/trace-macro.stderr | 2 +- .../usefulness/tuple-struct-nonexhaustive.stderr | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/library/std/src/macros.rs b/library/std/src/macros.rs index c597fb5df45d2..732acaa4186e8 100644 --- a/library/std/src/macros.rs +++ b/library/std/src/macros.rs @@ -99,9 +99,9 @@ macro_rules! println { () => { $crate::print!("\n") }; - ($($arg:tt)*) => { - $crate::io::_print($crate::format_args_nl!($($arg)*)) - }; + ($($arg:tt)*) => {{ + $crate::io::_print($crate::format_args_nl!($($arg)*)); + }}; } /// Prints to the standard error. @@ -164,9 +164,9 @@ macro_rules! eprintln { () => { $crate::eprint!("\n") }; - ($($arg:tt)*) => { - $crate::io::_eprint($crate::format_args_nl!($($arg)*)) - }; + ($($arg:tt)*) => {{ + $crate::io::_eprint($crate::format_args_nl!($($arg)*)); + }}; } /// Prints and returns the value of a given expression for quick and dirty diff --git a/src/test/pretty/dollar-crate.pp b/src/test/pretty/dollar-crate.pp index 0c96fb593e659..3af37955f2380 100644 --- a/src/test/pretty/dollar-crate.pp +++ b/src/test/pretty/dollar-crate.pp @@ -9,5 +9,5 @@ // pp-exact:dollar-crate.pp fn main() { - ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[])); + { ::std::io::_print(::core::fmt::Arguments::new_v1(&["rust\n"], &[])); }; } diff --git a/src/test/ui/macros/trace-macro.stderr b/src/test/ui/macros/trace-macro.stderr index c8a0fd684304e..43272248c280e 100644 --- a/src/test/ui/macros/trace-macro.stderr +++ b/src/test/ui/macros/trace-macro.stderr @@ -5,5 +5,5 @@ LL | println!("Hello, World!"); | ^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: expanding `println! { "Hello, World!" }` - = note: to `$crate :: io :: _print($crate :: format_args_nl! ("Hello, World!"))` + = note: to `{ $crate :: io :: _print($crate :: format_args_nl! ("Hello, World!")) ; }` diff --git a/src/test/ui/pattern/usefulness/tuple-struct-nonexhaustive.stderr b/src/test/ui/pattern/usefulness/tuple-struct-nonexhaustive.stderr index e2a65ff852404..fc0430d06fa1c 100644 --- a/src/test/ui/pattern/usefulness/tuple-struct-nonexhaustive.stderr +++ b/src/test/ui/pattern/usefulness/tuple-struct-nonexhaustive.stderr @@ -12,7 +12,7 @@ LL | struct Foo(isize, isize); = note: the matched value is of type `Foo` help: ensure that all possible cases are being handled by adding a match arm with a wildcard pattern or an explicit pattern as shown | -LL ~ Foo(2, b) => println!("{}", b), +LL ~ Foo(2, b) => println!("{}", b) LL + Foo(_, _) => todo!() | From e2d4c7b7c8c28d0b6ed55dc2f8f1aee05e7673d0 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sat, 30 Apr 2022 18:25:17 -0700 Subject: [PATCH 2/2] Revert "Bless coverage-reports after core macro blocks change" This reverts commit ac5c657a0801db84b29ea9b3ae322107756575b0. --- .../coverage-reports/expected_show_coverage.closure.txt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.closure.txt b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.closure.txt index 8bf9c97fddad4..e463099a5ee47 100644 --- a/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.closure.txt +++ b/src/test/run-make-fulldeps/coverage-reports/expected_show_coverage.closure.txt @@ -116,8 +116,8 @@ 116| 1| 117| 1| let 118| 1| _unused_closure - 119| 1| = - 120| 1| | + 119| | = + 120| | | 121| | mut countdown 122| | | 123| 0| { @@ -173,7 +173,7 @@ 169| | ; 170| | 171| 1| let short_used_not_covered_closure_line_break_no_block_embedded_branch = - 172| 1| | _unused_arg: u8 | + 172| | | _unused_arg: u8 | 173| 0| println!( 174| 0| "not called: {}", 175| 0| if is_true { "check" } else { "me" } @@ -191,7 +191,7 @@ 187| | ; 188| | 189| 1| let short_used_covered_closure_line_break_no_block_embedded_branch = - 190| | | _unused_arg: u8 | + 190| 1| | _unused_arg: u8 | 191| 1| println!( 192| 1| "not called: {}", 193| 1| if is_true { "check" } else { "me" }