]> git.lizzy.rs Git - rust.git/blob - src/test/ui/macros/colorful-write-macros.rs
Auto merge of #83152 - guswynn:jemallocator_part2, r=Mark-Simulacrum
[rust.git] / src / test / ui / macros / colorful-write-macros.rs
1 // run-pass
2 #![allow(dead_code)]
3 use std::io::Write;
4 use std::fmt;
5
6 struct Foo<'a> {
7     writer: &'a mut (dyn Write+'a),
8     other: &'a str,
9 }
10
11 struct Bar;
12
13 impl fmt::Write for Bar {
14     fn write_str(&mut self, _: &str) -> fmt::Result {
15         Ok(())
16     }
17 }
18
19 fn borrowing_writer_from_struct_and_formatting_struct_field(foo: Foo) {
20     write!(foo.writer, "{}", foo.other).unwrap();
21 }
22
23 fn main() {
24     let mut w = Vec::new();
25     write!(&mut w as &mut dyn Write, "").unwrap();
26     write!(&mut w, "").unwrap(); // should coerce
27     println!("ok");
28
29     let mut s = Bar;
30     {
31         use std::fmt::Write;
32         write!(&mut s, "test").unwrap();
33     }
34 }