Fix needless_raw_string_hashes miscounting hashes after two adjacent quotes - #17456
Conversation
|
Thanks for the pull request. A reviewer will take a look after it receives 2 community reviews. In the meantime, we would highly appreciate if you could try to review any of PRs waiting on community reviews. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
|
| following_quote = false; | ||
| let ended = req; | ||
| // a quote also starts a new run, e.g. `""#` requires two hashes | ||
| (following_quote, req) = (b == b'"', 1); |
There was a problem hiding this comment.
This is essentially what the first part of the match does currently under the precondition of the match.
Not sure if the code can be simplified, I did not find an clearly better solution 😆
A few sidegrades, but no clearly better one.
45e98fd to
27f2442
Compare
27f2442 to
8b92430
Compare
Fixes #11737
needless_raw_string_hashesscans the literal for the longest run of hashes following a quote, since that decides how many hashes the literal needs. The arm that starts a run is guarded byif !following_quote, so a second quote in a row falls through to the catch-all arm instead, which ends the run and clearsfollowing_quote. The hashes after that quote are then added to nothing, and the run they belong to is never counted.An empty inner raw string produces exactly that byte sequence, so
r##"{r#""#}"##was reported as needing only one hash. Applying the machine-applicable suggestion terminates the literal early at the inner"#and fails to compile witherror[E0765]: unterminated double quote string.The catch-all arm now starts a new run when the byte that ended the previous one is itself a quote.
changelog: [
needless_raw_string_hashes]: don't drop the hashes that follow two adjacent quotes