2 #![warn(clippy::explicit_write)]
3 #![allow(unused_imports)]
4 #![allow(clippy::uninlined_format_args)]
6 fn stdout() -> String {
10 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();
32 writeln!(std::io::stdout(), "test\ntest").unwrap();
33 writeln!(std::io::stderr(), "test\ntest").unwrap();
36 writeln!(std::io::stderr(), "with {}", value).unwrap();
37 writeln!(std::io::stderr(), "with {} {}", 2, value).unwrap();
38 writeln!(std::io::stderr(), "with {value}").unwrap();
39 writeln!(std::io::stderr(), "macro arg {}", one!()).unwrap();
41 writeln!(std::io::stderr(), "{:w$}", value, w = width).unwrap();
43 // these should not warn, different destination
46 let mut s = String::new();
47 write!(s, "test").unwrap();
48 write!(s, "test").unwrap();
49 writeln!(s, "test").unwrap();
50 writeln!(s, "test").unwrap();
51 s.write_fmt(format_args!("test")).unwrap();
52 s.write_fmt(format_args!("test")).unwrap();
53 write!(stdout(), "test").unwrap();
54 write!(stderr(), "test").unwrap();
55 writeln!(stdout(), "test").unwrap();
56 writeln!(stderr(), "test").unwrap();
57 stdout().write_fmt(format_args!("test")).unwrap();
58 stderr().write_fmt(format_args!("test")).unwrap();
60 // these should not warn, no unwrap
63 std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
64 std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");