]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/colorful-write-macros.rs
rollup merge of #20608: nikomatsakis/assoc-types-method-dispatch
[rust.git] / src / test / run-pass / colorful-write-macros.rs
1 // Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // no-pretty-expanded
12
13 #![allow(unused_must_use, dead_code, deprecated)]
14 #![feature(macro_rules)]
15
16 use std::io::MemWriter;
17 use std::fmt;
18
19 struct Foo<'a> {
20     writer: &'a mut (Writer+'a),
21     other: &'a str,
22 }
23
24 struct Bar;
25
26 impl fmt::Writer for Bar {
27     fn write_str(&mut self, _: &str) -> fmt::Result {
28         Ok(())
29     }
30 }
31
32 fn borrowing_writer_from_struct_and_formatting_struct_field(foo: Foo) {
33     write!(foo.writer, "{}", foo.other);
34 }
35
36 fn main() {
37     let mut w = MemWriter::new();
38     write!(&mut w as &mut Writer, "");
39     write!(&mut w, ""); // should coerce
40     println!("ok");
41
42     let mut s = Bar;
43     {
44         use std::fmt::Writer;
45         write!(&mut s, "test");
46     }
47 }