forked from rust-lang/rust
-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#6367 - justjosias:6348-print-stderr, r=ebroto
Add lint print_stderr Resolves rust-lang#6348 Almost identical to print_stdout, this lint applies to the `eprintln!` and `eprint!` macros rather than `println!` and `print!`. changelog: Add new lint [`print_stderr`]. [`println_empty_string`] and [`print_with_newline`] now apply to `eprint!()` and `eprintln!()` respectively.
- Loading branch information
Showing
10 changed files
with
294 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#![allow(clippy::print_literal)] | ||
#![warn(clippy::print_with_newline)] | ||
|
||
fn main() { | ||
eprint!("Hello\n"); | ||
eprint!("Hello {}\n", "world"); | ||
eprint!("Hello {} {}\n", "world", "#2"); | ||
eprint!("{}\n", 1265); | ||
eprint!("\n"); | ||
|
||
// these are all fine | ||
eprint!(""); | ||
eprint!("Hello"); | ||
eprintln!("Hello"); | ||
eprintln!("Hello\n"); | ||
eprintln!("Hello {}\n", "world"); | ||
eprint!("Issue\n{}", 1265); | ||
eprint!("{}", 1265); | ||
eprint!("\n{}", 1275); | ||
eprint!("\n\n"); | ||
eprint!("like eof\n\n"); | ||
eprint!("Hello {} {}\n\n", "world", "#2"); | ||
eprintln!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126 | ||
eprintln!("\nbla\n\n"); // #3126 | ||
|
||
// Escaping | ||
eprint!("\\n"); // #3514 | ||
eprint!("\\\n"); // should fail | ||
eprint!("\\\\n"); | ||
|
||
// Raw strings | ||
eprint!(r"\n"); // #3778 | ||
|
||
// Literal newlines should also fail | ||
eprint!( | ||
" | ||
" | ||
); | ||
eprint!( | ||
r" | ||
" | ||
); | ||
|
||
// Don't warn on CRLF (#4208) | ||
eprint!("\r\n"); | ||
eprint!("foo\r\n"); | ||
eprint!("\\r\n"); //~ ERROR | ||
eprint!("foo\rbar\n") // ~ ERROR | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:5:5 | ||
| | ||
LL | eprint!("Hello/n"); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::print-with-newline` implied by `-D warnings` | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!("Hello"); | ||
| ^^^^^^^^ -- | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:6:5 | ||
| | ||
LL | eprint!("Hello {}/n", "world"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!("Hello {}", "world"); | ||
| ^^^^^^^^ -- | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:7:5 | ||
| | ||
LL | eprint!("Hello {} {}/n", "world", "#2"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!("Hello {} {}", "world", "#2"); | ||
| ^^^^^^^^ -- | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:8:5 | ||
| | ||
LL | eprint!("{}/n", 1265); | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!("{}", 1265); | ||
| ^^^^^^^^ -- | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:9:5 | ||
| | ||
LL | eprint!("/n"); | ||
| ^^^^^^^^^^^^^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!(); | ||
| ^^^^^^^^ -- | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:28:5 | ||
| | ||
LL | eprint!("//n"); // should fail | ||
| ^^^^^^^^^^^^^^^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!("/"); // should fail | ||
| ^^^^^^^^ -- | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:35:5 | ||
| | ||
LL | / eprint!( | ||
LL | | " | ||
LL | | " | ||
LL | | ); | ||
| |_____^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!( | ||
LL | "" | ||
| | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:39:5 | ||
| | ||
LL | / eprint!( | ||
LL | | r" | ||
LL | | " | ||
LL | | ); | ||
| |_____^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!( | ||
LL | r"" | ||
| | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:47:5 | ||
| | ||
LL | eprint!("/r/n"); //~ ERROR | ||
| ^^^^^^^^^^^^^^^^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!("/r"); //~ ERROR | ||
| ^^^^^^^^ -- | ||
|
||
error: using `eprint!()` with a format string that ends in a single newline | ||
--> $DIR/eprint_with_newline.rs:48:5 | ||
| | ||
LL | eprint!("foo/rbar/n") // ~ ERROR | ||
| ^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: use `eprintln!` instead | ||
| | ||
LL | eprintln!("foo/rbar") // ~ ERROR | ||
| ^^^^^^^^ -- | ||
|
||
error: aborting due to 10 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#![warn(clippy::print_stderr)] | ||
|
||
fn main() { | ||
eprintln!("Hello"); | ||
println!("This should not do anything"); | ||
eprint!("World"); | ||
print!("Nor should this"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
error: use of `eprintln!` | ||
--> $DIR/print_stderr.rs:4:5 | ||
| | ||
LL | eprintln!("Hello"); | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `-D clippy::print-stderr` implied by `-D warnings` | ||
|
||
error: use of `eprint!` | ||
--> $DIR/print_stderr.rs:6:5 | ||
| | ||
LL | eprint!("World"); | ||
| ^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,11 @@ fn main() { | |
match "a" { | ||
_ => println!(), | ||
} | ||
|
||
eprintln!(); | ||
eprintln!(); | ||
|
||
match "a" { | ||
_ => eprintln!(), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,11 @@ fn main() { | |
match "a" { | ||
_ => println!(""), | ||
} | ||
|
||
eprintln!(); | ||
eprintln!(""); | ||
|
||
match "a" { | ||
_ => eprintln!(""), | ||
} | ||
} |
Oops, something went wrong.