2018-08-30 14:18:55 +02:00
|
|
|
// run-pass
|
2018-09-25 23:51:35 +02:00
|
|
|
#![allow(dead_code)]
|
2015-03-17 13:33:26 -07:00
|
|
|
use std::io::Write;
|
2014-05-16 22:40:38 -07:00
|
|
|
use std::fmt;
|
2014-02-13 04:31:19 -08:00
|
|
|
|
|
|
|
struct Foo<'a> {
|
2019-05-28 14:47:21 -04:00
|
|
|
writer: &'a mut (dyn Write+'a),
|
2014-02-13 04:31:19 -08:00
|
|
|
other: &'a str,
|
|
|
|
}
|
|
|
|
|
2014-05-16 22:40:38 -07:00
|
|
|
struct Bar;
|
|
|
|
|
2015-02-14 12:56:32 +13:00
|
|
|
impl fmt::Write for Bar {
|
2014-12-12 10:59:41 -08:00
|
|
|
fn write_str(&mut self, _: &str) -> fmt::Result {
|
2014-05-16 22:40:38 -07:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-13 04:31:19 -08:00
|
|
|
fn borrowing_writer_from_struct_and_formatting_struct_field(foo: Foo) {
|
2018-11-03 05:03:30 +00:00
|
|
|
write!(foo.writer, "{}", foo.other).unwrap();
|
2014-02-13 04:31:19 -08:00
|
|
|
}
|
|
|
|
|
2014-05-11 11:14:14 -07:00
|
|
|
fn main() {
|
2015-03-17 13:33:26 -07:00
|
|
|
let mut w = Vec::new();
|
2019-05-28 14:47:21 -04:00
|
|
|
write!(&mut w as &mut dyn Write, "").unwrap();
|
2018-11-03 05:03:30 +00:00
|
|
|
write!(&mut w, "").unwrap(); // should coerce
|
2014-05-11 11:14:14 -07:00
|
|
|
println!("ok");
|
2014-05-16 22:40:38 -07:00
|
|
|
|
|
|
|
let mut s = Bar;
|
2014-12-12 10:59:41 -08:00
|
|
|
{
|
2015-02-14 12:56:32 +13:00
|
|
|
use std::fmt::Write;
|
2018-11-03 05:03:30 +00:00
|
|
|
write!(&mut s, "test").unwrap();
|
2014-12-12 10:59:41 -08:00
|
|
|
}
|
2014-02-13 04:31:19 -08:00
|
|
|
}
|