summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/eprint_with_newline.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:02:58 +0000
commit698f8c2f01ea549d77d7dc3338a12e04c11057b9 (patch)
tree173a775858bd501c378080a10dca74132f05bc50 /src/tools/clippy/tests/ui/eprint_with_newline.rs
parentInitial commit. (diff)
downloadrustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.tar.xz
rustc-698f8c2f01ea549d77d7dc3338a12e04c11057b9.zip
Adding upstream version 1.64.0+dfsg1.upstream/1.64.0+dfsg1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/eprint_with_newline.rs')
-rw-r--r--src/tools/clippy/tests/ui/eprint_with_newline.rs49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/eprint_with_newline.rs b/src/tools/clippy/tests/ui/eprint_with_newline.rs
new file mode 100644
index 000000000..8df32649a
--- /dev/null
+++ b/src/tools/clippy/tests/ui/eprint_with_newline.rs
@@ -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
+}