]> git.lizzy.rs Git - rust.git/blob - tests/ui/explicit_write.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / explicit_write.rs
1 #![feature(tool_lints)]
2
3 #![warn(clippy::explicit_write)]
4
5
6 fn stdout() -> String {
7     String::new()
8 }
9
10 fn stderr() -> String {
11     String::new()
12 }
13
14 fn main() {
15     // these should warn
16     {
17         use std::io::Write;
18         write!(std::io::stdout(), "test").unwrap();
19         write!(std::io::stderr(), "test").unwrap();
20         writeln!(std::io::stdout(), "test").unwrap();
21         writeln!(std::io::stderr(), "test").unwrap();
22         std::io::stdout().write_fmt(format_args!("test")).unwrap();
23         std::io::stderr().write_fmt(format_args!("test")).unwrap();
24     }
25     // these should not warn, different destination
26     {
27         use std::fmt::Write;
28         let mut s = String::new();
29         write!(s, "test").unwrap();
30         write!(s, "test").unwrap();
31         writeln!(s, "test").unwrap();
32         writeln!(s, "test").unwrap();
33         s.write_fmt(format_args!("test")).unwrap();
34         s.write_fmt(format_args!("test")).unwrap();
35         write!(stdout(), "test").unwrap();
36         write!(stderr(), "test").unwrap();
37         writeln!(stdout(), "test").unwrap();
38         writeln!(stderr(), "test").unwrap();
39         stdout().write_fmt(format_args!("test")).unwrap();
40         stderr().write_fmt(format_args!("test")).unwrap();
41     }
42     // these should not warn, no unwrap
43     {
44         use std::io::Write;
45         std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
46         std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");
47     }
48 }