You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
write_literal doesn't correctly handle raw strings.
Reproducer
I tried this code:
writeln!(
pre,"{}",r#"$#CON colcheck "Use the sum of col {{index[0]}} for {{index[1]}}"find colcheck: matrix indexed by [int(1..width), ALLRANGE] of bool"#")?;
I expected write_literal to rewrite this to valid Rust. Instead, this happened:
writeln!(
pre,"$#CON colcheck \\"Use the sum of col {{{{index[0]}}}}for{{{{index[1]}}}}\\"
find colcheck: matrix indexed by [int(1..width),ALLRANGE] of bool")?;
My preference would be to just leave the raw string as is, I can't see why that wouldn't be the easist, and least-suprising option.
…estion (#13990)
fix#13959
The current implementation of the `write_literal` and `print_literal`
lint performs escaping for the second argument of `write!` ,`writeln!`,
`print!` and `println!` of the suggestion by first replacing `"` with
`\"`, and then replacing `\` with `\\`. Performing these replacements in
this order may lead to unnecessary backslashes being added if the
original code contains `"` (e.g. `"` -> `\\"`), potentially resulting in
a suggestion that causes the code to fail to compile.
In the issue mentioned above, it’s suggested to use raw strings as raw
strings, but implementing this would require an ad-hoc change to the
current implementation, so it has been deferred. (I'll implement this in
another PR)
changelog: [`write_literal`]: fix incorrect escaping of suggestions
changelog: [`print_literal`]: fix incorrect escaping of suggestions
Summary
write_literal doesn't correctly handle raw strings.
Reproducer
I tried this code:
I expected write_literal to rewrite this to valid Rust. Instead, this happened:
My preference would be to just leave the raw string as is, I can't see why that wouldn't be the easist, and least-suprising option.
Version
Additional Labels
No response
The text was updated successfully, but these errors were encountered: