-
Notifications
You must be signed in to change notification settings - Fork 13.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Warn about non-printable characters in string literals #63682
Comments
@rustbot modify labels: +A-parser, +A-diagnostics, +E-medium |
Attach the lint to |
@rustbot claim |
I'm not sure how to handle this: callers assume that errors |
Hm, indeed, One approach here is to extend the interface. I think something like this will be cleanest: struct EscapeError {
fallback: char,
kind: EscapeErrorKind,
}
impl EscapeErrorKind {
fn is_warning(&self) -> bool;
} That is, even if we emit error, we still produce a fallback char that should be inserted into the string. However, this particular warning can be handled with less machinery. At the call-site, we check if The benefit of the first approach is that it centralizes the knowledge about this warning to the The benefit of the second approach is simplicity. Moreover, it can be argued that warnings not necessary belong to rustc_lexer, as they don't affect the language definition. I personally would prefer to start with the second approach: it seems significantly easier to implement, and is very isolated, so changing it to the second one in the future would be easy. OTOH, starting with 2 and simplifying to 1 would be much harder to do. |
Added `non-printable-ascii` lint Closes #63682.
Triage: Hi, are you still working on this issue @Areredify? |
@Alexendoo nope, you can grab it, check out my pr earlier for reference if you want |
oh, sorry, it's a triage, I thought you wanted to grab it 😅 |
@rustbot release-assignment |
Currently a string literal with control characters like
\0
or\v
is accepted without any warnings. The only exception is\r
, which gives a hard error.It makes more sense to treat all non-printable, non \t, \n ASCII characters as a warning.
Steps to fix:
NonPrintableAsii
to EscapeErrorunespcape_error_reporting
. Note that, unlike other real errors, this one should be just a warning.I am not sure how to make this warning work with
#[allow]
lint infrastructure: we definitely can't do this in the lexer.The text was updated successfully, but these errors were encountered: