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 (
|
| b'"' if !following_quote => (following_quote, req) = (true, 1), | ||
| b'#' => req += u8::from(following_quote), | ||
| _ => { | ||
| if following_quote { |
There was a problem hiding this comment.
unrelated nit: I would appreciate this order, since this way reading why below is happening is simpler.
Took me longer than nessary to understand why below is happening 😉
| if following_quote { | |
| b'#' => req += u8::from(following_quote), | |
| b'"' if !following_quote => (following_quote, req) = (true, 1), | |
| _ if following_quote => { |
Github won't let me suggest this suggestion correctly, no clue why.
Should be clear enough though
| r##"task test(execute: "") {r#""#}"##; | ||
| r##"a quote pair followed by a hash: ""#"##; |
There was a problem hiding this comment.
lets also add the cases with the gap in the middle "just in case" to model the whole problem space in the tests, even though that already worked.
| 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.
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