-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Incorrect underline when format strings contain escaped characters #55155
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I'm working on a fix for this, but it might take some time because compiling rustc on my laptop takes ages. |
Sorry, it looks like I jumped the gun, I actually got stuck on this. The problem is that the code computing the spans only has access to the string after processing the escape sequences (which happens in the lexer) and we cannot get the correct offsets from that (we can't just map e.g. tabs to "\t" because the original string might have used a "\x"-style escape sequence instead. Or, for that matter, any regular character could have been expressed as an escape sequence, which would mess up the offsets). @estebank It looks to me like you introduced this functionality, do you have any ideas how this could be fixed? |
@fhartwig I believe we could pass around both the original and cooked strings around, and perform the span offset logic on the original, but I haven't looked at the code to see how hard that would be to do. I think that's the least hacky option. |
Yes, that seems to be the most plausible approach. One issue that I see with that is that the format characters themselves can be represented as escape sequences (i.e. |
@fhartwig indeed. I guess an option would be to have a fast-path parse where all of the current string parsing is done, and re-parse it with extra annotations if we encounter a problem. Having the diagnostics path be slower than the happy path is perfectly ok from my point of view. |
When a format string has escaped whitespace characters format arguments were shifted by one per each escaped character. Account for these escaped characters when synthesizing the spans. Fix rust-lang#55155.
When a format string has escaped whitespace characters format arguments were shifted by one per each escaped character. Account for these escaped characters when synthesizing the spans. Fix rust-lang#55155.
Playground
Output:
It seems the underline offset doesn't take into account that some characters like
"\n\t\r"
are wider in the source code.The text was updated successfully, but these errors were encountered: