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