Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)*) => {{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the back and forth here, it might be worth adding a comment that explains why a double brace is used?

$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