about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorDavid Tolnay <dtolnay@gmail.com>2022-04-26 15:00:36 -0700
committerDavid Tolnay <dtolnay@gmail.com>2022-05-22 16:11:08 -0700
commitae29890ab6a572fca53f693cccdf6654dd07f7d5 (patch)
tree029c3965c1ca091158a933512e24f3033b16b91b /src/test
parentb2eed72a6fbf254e7d44942eaa121fcbed05d3fb (diff)
downloadrust-ae29890ab6a572fca53f693cccdf6654dd07f7d5.tar.gz
rust-ae29890ab6a572fca53f693cccdf6654dd07f7d5.zip
Add test of temporaries inside format_args of core/std macros
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/macros/format-args-temporaries.rs70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/test/ui/macros/format-args-temporaries.rs b/src/test/ui/macros/format-args-temporaries.rs
new file mode 100644
index 00000000000..ddd4c9754bf
--- /dev/null
+++ b/src/test/ui/macros/format-args-temporaries.rs
@@ -0,0 +1,70 @@
+// check-pass
+
+use std::fmt::{self, Display};
+
+struct Mutex;
+
+impl Mutex {
+    fn lock(&self) -> MutexGuard {
+        MutexGuard(self)
+    }
+}
+
+struct MutexGuard<'a>(&'a Mutex);
+
+impl<'a> Drop for MutexGuard<'a> {
+    fn drop(&mut self) {
+        // Empty but this is a necessary part of the repro. Otherwise borrow
+        // checker is fine with 'a dangling at the time that MutexGuard goes out
+        // of scope.
+    }
+}
+
+impl<'a> MutexGuard<'a> {
+    fn write_fmt(&self, _args: fmt::Arguments) {}
+}
+
+impl<'a> Display for MutexGuard<'a> {
+    fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
+        Ok(())
+    }
+}
+
+fn main() {
+    let _write = {
+        let out = Mutex;
+        let mutex = Mutex;
+        write!(out.lock(), "{}", mutex.lock()) /* no semicolon */
+    };
+
+    let _writeln = {
+        let out = Mutex;
+        let mutex = Mutex;
+        writeln!(out.lock(), "{}", mutex.lock()) /* no semicolon */
+    };
+
+    let _print = {
+        let mutex = Mutex;
+        print!("{}", mutex.lock()) /* no semicolon */
+    };
+
+    let _println = {
+        let mutex = Mutex;
+        println!("{}", mutex.lock()) /* no semicolon */
+    };
+
+    let _eprint = {
+        let mutex = Mutex;
+        eprint!("{}", mutex.lock()) /* no semicolon */
+    };
+
+    let _eprintln = {
+        let mutex = Mutex;
+        eprintln!("{}", mutex.lock()) /* no semicolon */
+    };
+
+    let _panic = {
+        let mutex = Mutex;
+        panic!("{}", mutex.lock()) /* no semicolon */
+    };
+}