mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-02 08:16:07 +03:00
e9ede27a5d
These were probably added automatically to avoid code churn. I'd like to get rid of them bit by bit, so here's the first bit
78 lines
2.0 KiB
Rust
78 lines
2.0 KiB
Rust
#![warn(clippy::explicit_write)]
|
|
#![allow(unused_imports)]
|
|
|
|
fn stdout() -> String {
|
|
String::new()
|
|
}
|
|
|
|
fn stderr() -> String {
|
|
String::new()
|
|
}
|
|
|
|
macro_rules! one {
|
|
() => {
|
|
1
|
|
};
|
|
}
|
|
|
|
fn main() {
|
|
// these should warn
|
|
{
|
|
use std::io::Write;
|
|
print!("test");
|
|
//~^ explicit_write
|
|
eprint!("test");
|
|
//~^ explicit_write
|
|
println!("test");
|
|
//~^ explicit_write
|
|
eprintln!("test");
|
|
//~^ explicit_write
|
|
print!("test");
|
|
//~^ explicit_write
|
|
eprint!("test");
|
|
//~^ explicit_write
|
|
|
|
// including newlines
|
|
println!("test\ntest");
|
|
//~^ explicit_write
|
|
eprintln!("test\ntest");
|
|
//~^ explicit_write
|
|
|
|
let value = 1;
|
|
eprintln!("with {value}");
|
|
//~^ explicit_write
|
|
eprintln!("with {} {}", 2, value);
|
|
//~^ explicit_write
|
|
eprintln!("with {value}");
|
|
//~^ explicit_write
|
|
eprintln!("macro arg {}", one!());
|
|
//~^ explicit_write
|
|
let width = 2;
|
|
eprintln!("{value:w$}", w = width);
|
|
//~^ explicit_write
|
|
}
|
|
// 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");
|
|
}
|
|
}
|