1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
10 #![warn(clippy::explicit_write)]
12 fn stdout() -> String {
16 fn stderr() -> String {
24 write!(std::io::stdout(), "test").unwrap();
25 write!(std::io::stderr(), "test").unwrap();
26 writeln!(std::io::stdout(), "test").unwrap();
27 writeln!(std::io::stderr(), "test").unwrap();
28 std::io::stdout().write_fmt(format_args!("test")).unwrap();
29 std::io::stderr().write_fmt(format_args!("test")).unwrap();
31 // these should not warn, different destination
34 let mut s = String::new();
35 write!(s, "test").unwrap();
36 write!(s, "test").unwrap();
37 writeln!(s, "test").unwrap();
38 writeln!(s, "test").unwrap();
39 s.write_fmt(format_args!("test")).unwrap();
40 s.write_fmt(format_args!("test")).unwrap();
41 write!(stdout(), "test").unwrap();
42 write!(stderr(), "test").unwrap();
43 writeln!(stdout(), "test").unwrap();
44 writeln!(stderr(), "test").unwrap();
45 stdout().write_fmt(format_args!("test")).unwrap();
46 stderr().write_fmt(format_args!("test")).unwrap();
48 // these should not warn, no unwrap
51 std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
52 std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");