]> git.lizzy.rs Git - rust.git/blob - tests/ui/macros/format-args-temporaries.rs
Auto merge of #106952 - petrochenkov:docglob, r=notriddle,GuillaumeGomez
[rust.git] / tests / ui / macros / format-args-temporaries.rs
1 // check-pass
2
3 use std::fmt::{self, Display};
4
5 struct Mutex;
6
7 impl Mutex {
8     fn lock(&self) -> MutexGuard {
9         MutexGuard(self)
10     }
11 }
12
13 struct MutexGuard<'a>(&'a Mutex);
14
15 impl<'a> Drop for MutexGuard<'a> {
16     fn drop(&mut self) {
17         // Empty but this is a necessary part of the repro. Otherwise borrow
18         // checker is fine with 'a dangling at the time that MutexGuard goes out
19         // of scope.
20     }
21 }
22
23 impl<'a> Display for MutexGuard<'a> {
24     fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
25         Ok(())
26     }
27 }
28
29 fn main() {
30     let _print = {
31         let mutex = Mutex;
32         print!("{}", mutex.lock()) /* no semicolon */
33     };
34
35     let _println = {
36         let mutex = Mutex;
37         println!("{}", mutex.lock()) /* no semicolon */
38     };
39
40     let _eprint = {
41         let mutex = Mutex;
42         eprint!("{}", mutex.lock()) /* no semicolon */
43     };
44
45     let _eprintln = {
46         let mutex = Mutex;
47         eprintln!("{}", mutex.lock()) /* no semicolon */
48     };
49
50     let _panic = {
51         let mutex = Mutex;
52         panic!("{}", mutex.lock()) /* no semicolon */
53     };
54 }