mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
print_with_newline / write_with_newline: don't warn about string with several \n
s in them.
Fixes #3126
This commit is contained in:
parent
0a8ceaf8b0
commit
a0f56edfc3
@ -195,7 +195,10 @@ impl EarlyLintPass for Pass {
|
||||
} else if mac.node.path == "print" {
|
||||
span_lint(cx, PRINT_STDOUT, mac.span, "use of `print!`");
|
||||
if let Some(fmtstr) = check_tts(cx, &mac.node.tts, false).0 {
|
||||
if fmtstr.ends_with("\\n") && !fmtstr.ends_with("\\n\\n") {
|
||||
if fmtstr.ends_with("\\n") &&
|
||||
// don't warn about strings with several `\n`s (#3126)
|
||||
fmtstr.matches("\\n").count() == 1
|
||||
{
|
||||
span_lint(
|
||||
cx,
|
||||
PRINT_WITH_NEWLINE,
|
||||
@ -207,7 +210,10 @@ impl EarlyLintPass for Pass {
|
||||
}
|
||||
} else if mac.node.path == "write" {
|
||||
if let Some(fmtstr) = check_tts(cx, &mac.node.tts, true).0 {
|
||||
if fmtstr.ends_with("\\n") && !fmtstr.ends_with("\\n\\n") {
|
||||
if fmtstr.ends_with("\\n") &&
|
||||
// don't warn about strings with several `\n`s (#3126)
|
||||
fmtstr.matches("\\n").count() == 1
|
||||
{
|
||||
span_lint(
|
||||
cx,
|
||||
WRITE_WITH_NEWLINE,
|
||||
|
@ -21,4 +21,6 @@ fn main() {
|
||||
print!("\n\n");
|
||||
print!("like eof\n\n");
|
||||
print!("Hello {} {}\n\n", "world", "#2");
|
||||
println!("\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
|
||||
println!("\nbla\n\n"); // #3126
|
||||
}
|
||||
|
@ -26,4 +26,6 @@ fn main() {
|
||||
write!(&mut v, "\n\n");
|
||||
write!(&mut v, "like eof\n\n");
|
||||
write!(&mut v, "Hello {} {}\n\n", "world", "#2");
|
||||
writeln!(&mut v, "\ndon't\nwarn\nfor\nmultiple\nnewlines\n"); // #3126
|
||||
writeln!(&mut v, "\nbla\n\n"); // #3126
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user