Skip to content

Commit 40d9f1d

Browse files
committed
Add run-rustfix to explicit_write test
1 parent 9f8fb80 commit 40d9f1d

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

tests/ui/explicit_write.fixed

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
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+
fn main() {
14+
// these should warn
15+
{
16+
use std::io::Write;
17+
print!("test");
18+
eprint!("test");
19+
println!("test");
20+
eprintln!("test");
21+
print!("test");
22+
eprint!("test");
23+
24+
// including newlines
25+
println!("test\ntest");
26+
eprintln!("test\ntest");
27+
}
28+
// these should not warn, different destination
29+
{
30+
use std::fmt::Write;
31+
let mut s = String::new();
32+
write!(s, "test").unwrap();
33+
write!(s, "test").unwrap();
34+
writeln!(s, "test").unwrap();
35+
writeln!(s, "test").unwrap();
36+
s.write_fmt(format_args!("test")).unwrap();
37+
s.write_fmt(format_args!("test")).unwrap();
38+
write!(stdout(), "test").unwrap();
39+
write!(stderr(), "test").unwrap();
40+
writeln!(stdout(), "test").unwrap();
41+
writeln!(stderr(), "test").unwrap();
42+
stdout().write_fmt(format_args!("test")).unwrap();
43+
stderr().write_fmt(format_args!("test")).unwrap();
44+
}
45+
// these should not warn, no unwrap
46+
{
47+
use std::io::Write;
48+
std::io::stdout().write_fmt(format_args!("test")).expect("no stdout");
49+
std::io::stderr().write_fmt(format_args!("test")).expect("no stderr");
50+
}
51+
}

tests/ui/explicit_write.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// run-rustfix
2+
#![allow(unused_imports)]
13
#![warn(clippy::explicit_write)]
24

35
fn stdout() -> String {

tests/ui/explicit_write.stderr

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,49 @@
11
error: use of `write!(stdout(), ...).unwrap()`
2-
--> $DIR/explicit_write.rs:15:9
2+
--> $DIR/explicit_write.rs:17:9
33
|
44
LL | write!(std::io::stdout(), "test").unwrap();
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
66
|
77
= note: `-D clippy::explicit-write` implied by `-D warnings`
88

99
error: use of `write!(stderr(), ...).unwrap()`
10-
--> $DIR/explicit_write.rs:16:9
10+
--> $DIR/explicit_write.rs:18:9
1111
|
1212
LL | write!(std::io::stderr(), "test").unwrap();
1313
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
1414

1515
error: use of `writeln!(stdout(), ...).unwrap()`
16-
--> $DIR/explicit_write.rs:17:9
16+
--> $DIR/explicit_write.rs:19:9
1717
|
1818
LL | writeln!(std::io::stdout(), "test").unwrap();
1919
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test")`
2020

2121
error: use of `writeln!(stderr(), ...).unwrap()`
22-
--> $DIR/explicit_write.rs:18:9
22+
--> $DIR/explicit_write.rs:20:9
2323
|
2424
LL | writeln!(std::io::stderr(), "test").unwrap();
2525
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test")`
2626

2727
error: use of `stdout().write_fmt(...).unwrap()`
28-
--> $DIR/explicit_write.rs:19:9
28+
--> $DIR/explicit_write.rs:21:9
2929
|
3030
LL | std::io::stdout().write_fmt(format_args!("test")).unwrap();
3131
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `print!("test")`
3232

3333
error: use of `stderr().write_fmt(...).unwrap()`
34-
--> $DIR/explicit_write.rs:20:9
34+
--> $DIR/explicit_write.rs:22:9
3535
|
3636
LL | std::io::stderr().write_fmt(format_args!("test")).unwrap();
3737
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprint!("test")`
3838

3939
error: use of `writeln!(stdout(), ...).unwrap()`
40-
--> $DIR/explicit_write.rs:23:9
40+
--> $DIR/explicit_write.rs:25:9
4141
|
4242
LL | writeln!(std::io::stdout(), "test/ntest").unwrap();
4343
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `println!("test/ntest")`
4444

4545
error: use of `writeln!(stderr(), ...).unwrap()`
46-
--> $DIR/explicit_write.rs:24:9
46+
--> $DIR/explicit_write.rs:26:9
4747
|
4848
LL | writeln!(std::io::stderr(), "test/ntest").unwrap();
4949
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `eprintln!("test/ntest")`

0 commit comments

Comments
 (0)