Merge pull request #2131 from devonhollowood/suggest-print
Suggest print
This commit is contained in:
commit
f01e45faa4
4 changed files with 188 additions and 0 deletions
46
tests/ui/explicit_write.rs
Normal file
46
tests/ui/explicit_write.rs
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
#![warn(explicit_write)]
|
||||
|
||||
|
||||
fn stdout() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn stderr() -> String {
|
||||
String::new()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
// these should warn
|
||||
{
|
||||
use std::io::Write;
|
||||
write!(std::io::stdout(), "test").unwrap();
|
||||
write!(std::io::stderr(), "test").unwrap();
|
||||
writeln!(std::io::stdout(), "test").unwrap();
|
||||
writeln!(std::io::stderr(), "test").unwrap();
|
||||
std::io::stdout().write_fmt(format_args!("test")).unwrap();
|
||||
std::io::stderr().write_fmt(format_args!("test")).unwrap();
|
||||
}
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
38
tests/ui/explicit_write.stderr
Normal file
38
tests/ui/explicit_write.stderr
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
error: use of `write!(stdout(), ...).unwrap()`. Consider using `print!` instead
|
||||
--> $DIR/explicit_write.rs:16:9
|
||||
|
|
||||
16 | write!(std::io::stdout(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= note: `-D explicit-write` implied by `-D warnings`
|
||||
|
||||
error: use of `write!(stderr(), ...).unwrap()`. Consider using `eprint!` instead
|
||||
--> $DIR/explicit_write.rs:17:9
|
||||
|
|
||||
17 | write!(std::io::stderr(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of `writeln!(stdout(), ...).unwrap()`. Consider using `println!` instead
|
||||
--> $DIR/explicit_write.rs:18:9
|
||||
|
|
||||
18 | writeln!(std::io::stdout(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of `writeln!(stderr(), ...).unwrap()`. Consider using `eprintln!` instead
|
||||
--> $DIR/explicit_write.rs:19:9
|
||||
|
|
||||
19 | writeln!(std::io::stderr(), "test").unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of `stdout().write_fmt(...).unwrap()`. Consider using `print!` instead
|
||||
--> $DIR/explicit_write.rs:20:9
|
||||
|
|
||||
20 | std::io::stdout().write_fmt(format_args!("test")).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: use of `stderr().write_fmt(...).unwrap()`. Consider using `eprint!` instead
|
||||
--> $DIR/explicit_write.rs:21:9
|
||||
|
|
||||
21 | std::io::stderr().write_fmt(format_args!("test")).unwrap();
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue