From b68d3be8be46bea4b73321dd5f57e736e29e4362 Mon Sep 17 00:00:00 2001 From: Vastargazing Date: Fri, 24 Apr 2026 11:41:52 +0300 Subject: [PATCH] Add regression test for dbg! early drop of temporaries --- .../dbg-macro-temp-borrow.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-temp-borrow.rs diff --git a/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-temp-borrow.rs b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-temp-borrow.rs new file mode 100644 index 0000000000000..b101dbe165d80 --- /dev/null +++ b/tests/ui/rfcs/rfc-2361-dbg-macro/dbg-macro-temp-borrow.rs @@ -0,0 +1,19 @@ +//@ run-pass + +// Regression test for +// `dbg!` must not drop arguments' temporaries early in multi-arg form. + +fn id() -> i32 { + 42 +} + +fn main() { + assert_eq!(*dbg!(&id()), 42); + + assert_eq!(dbg!(0, &id()).0, 0); + assert_eq!(*dbg!(&id(), 1).0, 42); + assert_eq!(*dbg!(0, &id(), 2).1, 42); + + let f = || *dbg!(0, &id()).1; + assert_eq!(f(), 42); +} \ No newline at end of file