Skip to content

Commit cf5d4a1

Browse files
committed
Add failing test for #3778 write_with_newline
Literal `\n` characters (not a newline) in a `r"raw"` string should not fail the lint. This affects both write_with_newline and print_with_newline, so it is added in both places. I also copied a missing test case from write_with_newline over to print_with_newline and added a note that one of those tests is supposed to fail.
1 parent 2d28d9f commit cf5d4a1

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

tests/ui/print_with_newline.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,12 @@ fn main() {
2121
print!("Hello {} {}\n\n", "world", "#2");
2222
println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
2323
println!("\nbla\n\n"); // #3126
24+
25+
// Escaping
26+
print!("\\n"); // #3514
27+
print!("\\\n"); // should fail
28+
print!("\\\\n");
29+
30+
// Raw strings
31+
print!(r"\n"); // #3778
2432
}

tests/ui/print_with_newline.stderr

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,11 @@ error: using `print!()` with a format string that ends in a single newline, cons
2424
LL | print!("{}/n", 1265);
2525
| ^^^^^^^^^^^^^^^^^^^^
2626

27-
error: aborting due to 4 previous errors
27+
error: using `print!()` with a format string that ends in a single newline, consider using `println!()` instead
28+
--> $DIR/print_with_newline.rs:27:5
29+
|
30+
LL | print!("//n"); // should fail
31+
| ^^^^^^^^^^^^^^
32+
33+
error: aborting due to 5 previous errors
2834

tests/ui/write_with_newline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ fn main() {
2929

3030
// Escaping
3131
write!(&mut v, "\\n"); // #3514
32-
write!(&mut v, "\\\n");
32+
write!(&mut v, "\\\n"); // should fail
3333
write!(&mut v, "\\\\n");
3434

3535
// Raw strings

tests/ui/write_with_newline.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ LL | write!(&mut v, "{}/n", 1265);
2727
error: using `write!()` with a format string that ends in a single newline, consider using `writeln!()` instead
2828
--> $DIR/write_with_newline.rs:32:5
2929
|
30-
LL | write!(&mut v, "//n");
30+
LL | write!(&mut v, "//n"); // should fail
3131
| ^^^^^^^^^^^^^^^^^^^^^^
3232

3333
error: aborting due to 5 previous errors

0 commit comments

Comments
 (0)