Skip to content

Commit

Permalink
Add run-rustfix to explicit_write test
Browse files Browse the repository at this point in the history
  • Loading branch information
detrumi committed Jan 13, 2019
1 parent 9f8fb80 commit 40d9f1d
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 8 deletions.
51 changes: 51 additions & 0 deletions tests/ui/explicit_write.fixed
@@ -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");
}
}
2 changes: 2 additions & 0 deletions tests/ui/explicit_write.rs
@@ -1,3 +1,5 @@
// run-rustfix
#![allow(unused_imports)]
#![warn(clippy::explicit_write)]

fn stdout() -> String {
Expand Down
16 changes: 8 additions & 8 deletions tests/ui/explicit_write.stderr
@@ -1,49 +1,49 @@
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")`
|
= 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")`
Expand Down

0 comments on commit 40d9f1d

Please sign in to comment.