mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-23 05:03:21 +00:00
Add run-rustfix to explicit_write test
This commit is contained in:
parent
9f8fb8007c
commit
40d9f1d9f4
3 changed files with 61 additions and 8 deletions
51
tests/ui/explicit_write.fixed
Normal file
51
tests/ui/explicit_write.fixed
Normal file
|
@ -0,0 +1,51 @@
|
|||
// run-rustfix
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::explicit_write)]
|
||||
|
||||
fn stdout() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn stderr() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
}
|
|
@ -1,3 +1,5 @@
|
|||
// run-rustfix
|
||||
#![allow(unused_imports)]
|
||||
#![warn(clippy::explicit_write)]
|
||||
|
||||
fn stdout() -> String {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: use of `write!(stdout(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:15:9
|
||||
--> $DIR/explicit_write.rs:17:9
|
||||
|
|
||||
LL | write!(std::io::stdout(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
|
||||
|
@ -7,43 +7,43 @@ LL | write!(std::io::stdout(), "test").unwrap();
|
|||
= note: `-D clippy::explicit-write` implied by `-D warnings`
|
||||
|
||||
error: use of `write!(stderr(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:16:9
|
||||
--> $DIR/explicit_write.rs:18:9
|
||||
|
|
||||
LL | write!(std::io::stderr(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
|
||||
|
||||
error: use of `writeln!(stdout(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:17:9
|
||||
--> $DIR/explicit_write.rs:19:9
|
||||
|
|
||||
LL | writeln!(std::io::stdout(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test")`
|
||||
|
||||
error: use of `writeln!(stderr(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:18:9
|
||||
--> $DIR/explicit_write.rs:20:9
|
||||
|
|
||||
LL | writeln!(std::io::stderr(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test")`
|
||||
|
||||
error: use of `stdout().write_fmt(...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:19:9
|
||||
--> $DIR/explicit_write.rs:21:9
|
||||
|
|
||||
LL | std::io::stdout().write_fmt(format_args!("test")).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
|
||||
|
||||
error: use of `stderr().write_fmt(...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:20:9
|
||||
--> $DIR/explicit_write.rs:22:9
|
||||
|
|
||||
LL | std::io::stderr().write_fmt(format_args!("test")).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
|
||||
|
||||
error: use of `writeln!(stdout(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:23:9
|
||||
--> $DIR/explicit_write.rs:25:9
|
||||
|
|
||||
LL | writeln!(std::io::stdout(), "test/ntest").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test/ntest")`
|
||||
|
||||
error: use of `writeln!(stderr(), ...).unwrap()`
|
||||
--> $DIR/explicit_write.rs:24:9
|
||||
--> $DIR/explicit_write.rs:26:9
|
||||
|
|
||||
LL | writeln!(std::io::stderr(), "test/ntest").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test/ntest")`
|
||||
|
|
Loading…
Reference in a new issue