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.
13 #![warn(clippy::explicit_write)]
16 fn stdout() -> String {
20 fn stderr() -> String {
28 write!(std::io::stdout(), "test").unwrap();
29 write!(std::io::stderr(), "test").unwrap();
30 writeln!(std::io::stdout(), "test").unwrap();
31 writeln!(std::io::stderr(), "test").unwrap();
32 std::io::stdout().write_fmt(format_args!("test")).unwrap();
33 std::io::stderr().write_fmt(format_args!("test")).unwrap();
35 // these should not warn, different destination
38 let mut s = String::new();
39 write!(s, "test").unwrap();
40 write!(s, "test").unwrap();
41 writeln!(s, "test").unwrap();
42 writeln!(s, "test").unwrap();
43 s.write_fmt(format_args!("test")).unwrap();
44 s.write_fmt(format_args!("test")).unwrap();
45 write!(stdout(), "test").unwrap();
46 write!(stderr(), "test").unwrap();
47 writeln!(stdout(), "test").unwrap();
48 writeln!(stderr(), "test").unwrap();
49 stdout().write_fmt(format_args!("test")).unwrap();
50 stderr().write_fmt(format_args!("test")).unwrap();
52 // these should not warn, no unwrap
55 std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
56 std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");