Skip to content

Commit 61469b6

Browse files
committed
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, "…", …)` | :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:
2 parents bf61143 + e2d4c7b commit 61469b6

File tree

5 files changed

+13
-13
lines changed

5 files changed

+13
-13
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/run-make-fulldeps/coverage-reports/expected_show_coverage.closure.txt

+4-4
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@
116116
116| 1|
117117
117| 1| let
118118
118| 1| _unused_closure
119-
119| 1| =
120-
120| 1| |
119+
119| | =
120+
120| | |
121121
121| | mut countdown
122122
122| | |
123123
123| 0| {
@@ -173,7 +173,7 @@
173173
169| | ;
174174
170| |
175175
171| 1| let short_used_not_covered_closure_line_break_no_block_embedded_branch =
176-
172| 1| | _unused_arg: u8 |
176+
172| | | _unused_arg: u8 |
177177
173| 0| println!(
178178
174| 0| "not called: {}",
179179
175| 0| if is_true { "check" } else { "me" }
@@ -191,7 +191,7 @@
191191
187| | ;
192192
188| |
193193
189| 1| let short_used_covered_closure_line_break_no_block_embedded_branch =
194-
190| | | _unused_arg: u8 |
194+
190| 1| | _unused_arg: u8 |
195195
191| 1| println!(
196196
192| 1| "not called: {}",
197197
193| 1| if is_true { "check" } else { "me" }

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)