rust/tests/ui/macros/colorful-write-macros.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
653 B
Rust
Raw Normal View History

// run-pass
#![allow(dead_code)]
use std::io::Write;
use std::fmt;
struct Foo<'a> {
2019-05-29 02:47:21 +08:00
writer: &'a mut (dyn Write+'a),
other: &'a str,
}
struct Bar;
impl fmt::Write for Bar {
fn write_str(&mut self, _: &str) -> fmt::Result {
Ok(())
}
}
fn borrowing_writer_from_struct_and_formatting_struct_field(foo: Foo) {
2018-11-03 13:03:30 +08:00
write!(foo.writer, "{}", foo.other).unwrap();
}
fn main() {
let mut w = Vec::new();
2019-05-29 02:47:21 +08:00
write!(&mut w as &mut dyn Write, "").unwrap();
2018-11-03 13:03:30 +08:00
write!(&mut w, "").unwrap(); // should coerce
println!("ok");
let mut s = Bar;
{
use std::fmt::Write;
2018-11-03 13:03:30 +08:00
write!(&mut s, "test").unwrap();
}
}