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