fix escaping problem in write_literal and print_literal lint

This commit is contained in:
lapla-cogito 2025-01-13 05:31:12 +09:00
parent 716a3a4778
commit 65b95a2cfb
No known key found for this signature in database
GPG key ID: B39C71D9F127FF9F
7 changed files with 137 additions and 3 deletions

View file

@ -66,3 +66,17 @@ fn main() {
println!("mixed: {{hello}} {world}");
}
fn issue_13959() {
println!("\"");
println!(
"
foo
\\
\\\\
\"
\\\"
bar
"
);
}

View file

@ -66,3 +66,18 @@ fn main() {
println!("mixed: {} {world}", "{hello}");
}
fn issue_13959() {
println!("{}", r#"""#);
println!(
"{}",
r#"
foo
\
\\
"
\"
bar
"#
);
}

View file

@ -192,5 +192,41 @@ LL - println!("mixed: {} {world}", "{hello}");
LL + println!("mixed: {{hello}} {world}");
|
error: aborting due to 16 previous errors
error: literal with an empty format string
--> tests/ui/print_literal.rs:71:20
|
LL | println!("{}", r#"""#);
| ^^^^^^
|
help: try
|
LL - println!("{}", r#"""#);
LL + println!("\"");
|
error: literal with an empty format string
--> tests/ui/print_literal.rs:74:9
|
LL | / r#"
LL | | foo
LL | | \
LL | | \\
... |
LL | | bar
LL | | "#
| |__^
|
help: try
|
LL ~ "
LL + foo
LL + \\
LL + \\\\
LL + \"
LL + \\\"
LL + bar
LL ~ "
|
error: aborting due to 18 previous errors

View file

@ -62,3 +62,19 @@ fn main() {
writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4);
//~^ ERROR: literal with an empty format string
}
fn issue_13959() {
let mut v = Vec::new();
writeln!(v, "\"");
writeln!(
v,
"
foo
\\
\\\\
\"
\\\"
bar
"
);
}

View file

@ -62,3 +62,20 @@ fn main() {
writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4);
//~^ ERROR: literal with an empty format string
}
fn issue_13959() {
let mut v = Vec::new();
writeln!(v, "{}", r#"""#);
writeln!(
v,
"{}",
r#"
foo
\
\\
"
\"
bar
"#
);
}

View file

@ -144,5 +144,41 @@ LL - writeln!(v, "{0} {1} {2}, {3} {4}", "hello", 2, 3, "world", 4);
LL + writeln!(v, "hello {0} {1}, world {2}", 2, 3, 4);
|
error: aborting due to 12 previous errors
error: literal with an empty format string
--> tests/ui/write_literal.rs:68:23
|
LL | writeln!(v, "{}", r#"""#);
| ^^^^^^
|
help: try
|
LL - writeln!(v, "{}", r#"""#);
LL + writeln!(v, "\"");
|
error: literal with an empty format string
--> tests/ui/write_literal.rs:72:9
|
LL | / r#"
LL | | foo
LL | | \
LL | | \\
... |
LL | | bar
LL | | "#
| |__^
|
help: try
|
LL ~ "
LL + foo
LL + \\
LL + \\\\
LL + \"
LL + \\\"
LL + bar
LL ~ "
|
error: aborting due to 14 previous errors