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