Skip to content

Commit

Permalink
Auto merge of rust-lang#96490 - dtolnay:writetmpbackport, r=Mark-Simu…
Browse files Browse the repository at this point in the history
…lacrum

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

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

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

argument position | before rust-lang#94868 | after rust-lang#94868 | after this PR
--- |:---:|:---:|:---:
`write!($tmp, "…", …)` | :rage: | :rage: | :rage:
`write!(…, "…", $tmp)` | :rage: | :rage: | :rage:
`writeln!($tmp, "…", …)` | :rage: | :rage: | :rage:
`writeln!(…, "…", $tmp)` | :rage: | :rage: | :rage:
`print!("…", $tmp)` | :rage: | :rage: | :rage:
`println!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat:
`eprint!("…", $tmp)` | :rage: | :rage: | :rage:
`eprintln!("…", $tmp)` | :smiley_cat: | :rage: | :smiley_cat:
`panic!("…", $tmp)` | :smiley_cat: | :smiley_cat: | :smiley_cat:
  • Loading branch information
bors authored and MabezDev committed May 17, 2022
1 parent bed7d84 commit 6dc86ec
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
12 changes: 6 additions & 6 deletions library/std/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/pretty/dollar-crate.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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"], &[])); };
}
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down Expand Up @@ -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" }
Expand All @@ -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" }
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/macros/trace-macro.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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!")) ; }`

Original file line number Diff line number Diff line change
Expand Up @@ -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!()
|

Expand Down

0 comments on commit 6dc86ec

Please sign in to comment.