2023-04-20 09:37:15 -05:00
|
|
|
//@run-rustfix
|
2019-01-13 05:22:59 -06:00
|
|
|
#![warn(clippy::explicit_write)]
|
2022-10-02 14:13:22 -05:00
|
|
|
#![allow(unused_imports)]
|
|
|
|
#![allow(clippy::uninlined_format_args)]
|
2019-01-13 05:22:59 -06:00
|
|
|
|
|
|
|
fn stdout() -> String {
|
|
|
|
String::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
fn stderr() -> String {
|
|
|
|
String::new()
|
|
|
|
}
|
|
|
|
|
2022-01-28 08:58:14 -06:00
|
|
|
macro_rules! one {
|
|
|
|
() => {
|
|
|
|
1
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-01-13 05:22:59 -06:00
|
|
|
fn main() {
|
|
|
|
// these should warn
|
|
|
|
{
|
|
|
|
use std::io::Write;
|
|
|
|
print!("test");
|
|
|
|
eprint!("test");
|
|
|
|
println!("test");
|
|
|
|
eprintln!("test");
|
|
|
|
print!("test");
|
|
|
|
eprint!("test");
|
|
|
|
|
|
|
|
// including newlines
|
|
|
|
println!("test\ntest");
|
|
|
|
eprintln!("test\ntest");
|
2022-01-28 08:58:14 -06:00
|
|
|
|
|
|
|
let value = 1;
|
|
|
|
eprintln!("with {}", value);
|
|
|
|
eprintln!("with {} {}", 2, value);
|
|
|
|
eprintln!("with {value}");
|
|
|
|
eprintln!("macro arg {}", one!());
|
2022-09-12 06:34:09 -05:00
|
|
|
let width = 2;
|
|
|
|
eprintln!("{:w$}", value, w = width);
|
2019-01-13 05:22:59 -06:00
|
|
|
}
|
|
|
|
// these should not warn, different destination
|
|
|
|
{
|
|
|
|
use std::fmt::Write;
|
|
|
|
let mut s = String::new();
|
|
|
|
write!(s, "test").unwrap();
|
|
|
|
write!(s, "test").unwrap();
|
|
|
|
writeln!(s, "test").unwrap();
|
|
|
|
writeln!(s, "test").unwrap();
|
|
|
|
s.write_fmt(format_args!("test")).unwrap();
|
|
|
|
s.write_fmt(format_args!("test")).unwrap();
|
|
|
|
write!(stdout(), "test").unwrap();
|
|
|
|
write!(stderr(), "test").unwrap();
|
|
|
|
writeln!(stdout(), "test").unwrap();
|
|
|
|
writeln!(stderr(), "test").unwrap();
|
|
|
|
stdout().write_fmt(format_args!("test")).unwrap();
|
|
|
|
stderr().write_fmt(format_args!("test")).unwrap();
|
|
|
|
}
|
|
|
|
// these should not warn, no unwrap
|
|
|
|
{
|
|
|
|
use std::io::Write;
|
|
|
|
std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
|
|
|
|
std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");
|
|
|
|
}
|
|
|
|
}
|