]> git.lizzy.rs Git - rust.git/blob - src/tools/clippy/tests/ui/explicit_write.fixed
:arrow_up: rust-analyzer
[rust.git] / src / tools / clippy / 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 macro_rules! one {
14     () => {
15         1
16     };
17 }
18
19 fn main() {
20     // these should warn
21     {
22         use std::io::Write;
23         print!("test");
24         eprint!("test");
25         println!("test");
26         eprintln!("test");
27         print!("test");
28         eprint!("test");
29
30         // including newlines
31         println!("test\ntest");
32         eprintln!("test\ntest");
33
34         let value = 1;
35         eprintln!("with {}", value);
36         eprintln!("with {} {}", 2, value);
37         eprintln!("with {value}");
38         eprintln!("macro arg {}", one!());
39     }
40     // these should not warn, different destination
41     {
42         use std::fmt::Write;
43         let mut s = String::new();
44         write!(s, "test").unwrap();
45         write!(s, "test").unwrap();
46         writeln!(s, "test").unwrap();
47         writeln!(s, "test").unwrap();
48         s.write_fmt(format_args!("test")).unwrap();
49         s.write_fmt(format_args!("test")).unwrap();
50         write!(stdout(), "test").unwrap();
51         write!(stderr(), "test").unwrap();
52         writeln!(stdout(), "test").unwrap();
53         writeln!(stderr(), "test").unwrap();
54         stdout().write_fmt(format_args!("test")).unwrap();
55         stderr().write_fmt(format_args!("test")).unwrap();
56     }
57     // these should not warn, no unwrap
58     {
59         use std::io::Write;
60         std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
61         std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");
62     }
63 }