Auto merge of #96490 - dtolnay:writetmpbackport, r=Mark-Simulacrum

Make [e]println macros eagerly drop temporaries (for backport)

This PR extracts the subset of #96455 which is only the parts necessary for fixing the 1.61-beta regressions in #96434.

My larger PR #96455 contains a few other changes relative to the pre-#94868 behavior; those are not necessary to backport into 1.61.

argument position | before #94868 | after #94868 | after this PR
--- |:---:|:---:|:---:
`write!($tmp, "…", …)` | 😡 | 😡 | 😡
`write!(…, "…", $tmp)` | 😡 | 😡 | 😡
`writeln!($tmp, "…", …)` | 😡 | 😡 | 😡
`writeln!(…, "…", $tmp)` | 😡 | 😡 | 😡
`print!("…", $tmp)` | 😡 | 😡 | 😡
`println!("…", $tmp)` | 😺 | 😡 | 😺
`eprint!("…", $tmp)` | 😡 | 😡 | 😡
`eprintln!("…", $tmp)` | 😺 | 😡 | 😺
`panic!("…", $tmp)` | 😺 | 😺 | 😺
This commit is contained in:
bors 2022-05-01 03:18:53 +00:00
commit 61469b682c
5 changed files with 13 additions and 13 deletions

View File

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

View File

@ -9,5 +9,5 @@ extern crate std;
// 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"], &[])); };
}

View File

@ -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" }

View File

@ -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!")) ; }`

View File

@ -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!()
|