]> git.lizzy.rs Git - rust.git/blob - tests/ui/macros/format-args-temporaries-in-write.rs
Rollup merge of #106931 - Ezrashaw:docs-e0208, r=compiler-errors
[rust.git] / tests / ui / macros / format-args-temporaries-in-write.rs
1 // check-fail
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 struct Out;
24
25 impl Out {
26     fn write_fmt(&self, _args: fmt::Arguments) {}
27 }
28
29 impl<'a> Display for MutexGuard<'a> {
30     fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
31         Ok(())
32     }
33 }
34
35 fn main() {
36     // FIXME(dtolnay): We actually want both of these to work. I think it's
37     // sadly unimplementable today though.
38
39     let _write = {
40         let mutex = Mutex;
41         write!(Out, "{}", mutex.lock()) /* no semicolon */
42         //~^ ERROR `mutex` does not live long enough
43     };
44
45     let _writeln = {
46         let mutex = Mutex;
47         writeln!(Out, "{}", mutex.lock()) /* no semicolon */
48         //~^ ERROR `mutex` does not live long enough
49     };
50 }