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.
This commit is contained in:
@@ -21,4 +21,12 @@ fn main() {
|
|||||||
print!("Hello {} {}\n\n", "world", "#2");
|
print!("Hello {} {}\n\n", "world", "#2");
|
||||||
println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
|
println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
|
||||||
println!("\nbla\n\n"); // #3126
|
println!("\nbla\n\n"); // #3126
|
||||||
|
|
||||||
|
// Escaping
|
||||||
|
print!("\\n"); // #3514
|
||||||
|
print!("\\\n"); // should fail
|
||||||
|
print!("\\\\n");
|
||||||
|
|
||||||
|
// Raw strings
|
||||||
|
print!(r"\n"); // #3778
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,5 +24,11 @@ error: using `print!()` with a format string that ends in a single newline, cons
|
|||||||
LL | print!("{}/n", 1265);
|
LL | print!("{}/n", 1265);
|
||||||
| ^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: using `print!()` with a format string that ends in a single newline, consider using `println!()` instead
|
||||||
|
--> $DIR/print_with_newline.rs:27:5
|
||||||
|
|
|
||||||
|
LL | print!("//n"); // should fail
|
||||||
|
| ^^^^^^^^^^^^^^
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ fn main() {
|
|||||||
|
|
||||||
// Escaping
|
// Escaping
|
||||||
write!(&mut v, "\\n"); // #3514
|
write!(&mut v, "\\n"); // #3514
|
||||||
write!(&mut v, "\\\n");
|
write!(&mut v, "\\\n"); // should fail
|
||||||
write!(&mut v, "\\\\n");
|
write!(&mut v, "\\\\n");
|
||||||
|
|
||||||
// Raw strings
|
// Raw strings
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ LL | write!(&mut v, "{}/n", 1265);
|
|||||||
error: using `write!()` with a format string that ends in a single newline, consider using `writeln!()` instead
|
error: using `write!()` with a format string that ends in a single newline, consider using `writeln!()` instead
|
||||||
--> $DIR/write_with_newline.rs:32:5
|
--> $DIR/write_with_newline.rs:32:5
|
||||||
|
|
|
|
||||||
LL | write!(&mut v, "//n");
|
LL | write!(&mut v, "//n"); // should fail
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^^
|
| ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|||||||
Reference in New Issue
Block a user