]> git.lizzy.rs Git - rust.git/blob - tests/ui/explicit_write.fixed
Auto merge of #4478 - tsurai:master, r=flip1995
[rust.git] / tests / ui / explicit_write.fixed
1 // run-rustfix
2 #![allow(unused_imports)]
3 #![warn(clippy::explicit_write)]
4
5 fn stdout() -> String {
6     String::new()
7 }
8
9 fn stderr() -> String {
10     String::new()
11 }
12
13 fn main() {
14     // these should warn
15     {
16         use std::io::Write;
17         print!("test");
18         eprint!("test");
19         println!("test");
20         eprintln!("test");
21         print!("test");
22         eprint!("test");
23
24         // including newlines
25         println!("test\ntest");
26         eprintln!("test\ntest");
27     }
28     // these should not warn, different destination
29     {
30         use std::fmt::Write;
31         let mut s = String::new();
32         write!(s, "test").unwrap();
33         write!(s, "test").unwrap();
34         writeln!(s, "test").unwrap();
35         writeln!(s, "test").unwrap();
36         s.write_fmt(format_args!("test")).unwrap();
37         s.write_fmt(format_args!("test")).unwrap();
38         write!(stdout(), "test").unwrap();
39         write!(stderr(), "test").unwrap();
40         writeln!(stdout(), "test").unwrap();
41         writeln!(stderr(), "test").unwrap();
42         stdout().write_fmt(format_args!("test")).unwrap();
43         stderr().write_fmt(format_args!("test")).unwrap();
44     }
45     // these should not warn, no unwrap
46     {
47         use std::io::Write;
48         std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
49         std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");
50     }
51 }