Revert "Rollup merge of #154994 - dianne:no-dbg-temp, r=Mark-Simulacrum"

This reverts commit 59b36a5283, reversing
changes made to 197eb8c6c0.

(cherry picked from commit 73931c4422)
This commit is contained in:
Josh Stone
2026-05-14 15:36:33 -07:00
parent 6be5f81e16
commit 01f6bb52b3
2 changed files with 2 additions and 29 deletions
+2 -5
View File
@@ -369,8 +369,7 @@ macro_rules! dbg {
/// E.g. `dbg_internal!(() () (1, 2))` expands into
/// ```rust, ignore
/// match (1, 2) {
/// args => {
/// let (tmp_1, tmp_2) = args;
/// (tmp_1, tmp_2) => {
/// eprint!("...", &tmp_1, &tmp_2, /* some other arguments */);
/// (tmp_1, tmp_2)
/// }
@@ -386,9 +385,7 @@ macro_rules! dbg {
// of temporaries - https://stackoverflow.com/a/48732525/1063961
// Always put the arguments in a tuple to avoid an unused parens lint on the pattern.
match ($($processed,)+) {
// Move the entire tuple so it doesn't stick around as a temporary (#154988).
args => {
let ($($bound,)+) = args;
($($bound,)+) => {
$crate::eprint!(
$crate::concat!($($piece),+),
$(
-24
View File
@@ -1,7 +1,5 @@
// ignore-tidy-dbg
use core::fmt::Debug;
/// Test for <https://github.com/rust-lang/rust/issues/153850>:
/// `dbg!` shouldn't drop arguments' temporaries.
#[test]
@@ -13,25 +11,3 @@ fn temp() {}
*dbg!(0, &temp()).1;
*dbg!(0, &temp(), 2).1;
}
/// Test for <https://github.com/rust-lang/rust/issues/154988>:
/// `dbg!` shouldn't create a temporary that lives past its invocation.
#[test]
fn no_leaking_internal_temps_from_dbg() {
#[derive(Debug)]
struct Foo;
#[derive(Debug)]
struct Bar<'a>(#[allow(unused)] &'a Foo);
impl Drop for Bar<'_> {
fn drop(&mut self) {}
}
let foo = Foo;
let bar = Bar(&foo);
// If `dbg!` creates a `(Bar<'_>,)` temporary that lasts past its expansion, this will fail
// to compile, because it will be dropped after `foo`, which it borrows from. The tuple
// mimics the drop order of block tail expressions before Rust 2024: first the result of `dbg!`
// is dropped, then `foo`, then any temporaries left over from `dbg!` are dropped, if present.
(drop(dbg!(bar)), drop(foo));
}