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
Currently string literals are unescaped twice.
- Once during lexing in `cook_quoted`/`cook_c_string`/`cook_common`.
This one just checks for errors.
- Again in `LitKind::from_token_lit`, which is called when lowering AST
to HIR, and also in a few other places during expansion. This one
actually constructs the unescaped string. It also has error checking
code, but that part of the code is actually dead (and has several
bugs) because the check during lexing catches all errors!
This commit removes the error-check-only unescaping during lexing, and
fixes up `LitKind::from_token_lit` so it properly does both checking and
construction. This is a backwards-compatible language change: some
programs now compile that previously did not. For example, it is now
possible for macros to consume "invalid" string literals like "\a\b\c".
This is a continuation of a trend of delaying semantic error checking of
literals to after expansion:
- rust-lang#102944 did this for some cases for numeric literals
- The detection of NUL chars in C string literals is already delayed in
this way.
Notes about test changes:
- `ignore-block-help.rs`: this requires a parse error for the test to
work. The error used was an unescaping error, which is now delayed to
after parsing. So the commit changes it to an "unterminated character
literal" error which still occurs during parsing.
- `tests/ui/lexer/error-stage.rs`: this shows the newly allowed cases,
due to delayed literal unescaping.
- Several tests had unescaping errors combined with unterminated literal
errors. The former are now delayed but the latter remain as lexing
errors. So the unterminated literal part needed to be split into a
separate test file otherwise compilation would end before the other
errors were reported.
- issue-62913.rs: The structure and output changed a bit. Issue rust-lang#62913
was about an ICE due to an unterminated string literal, so the new
version should be good enough.
- literals-are-validated-before-expansion.rs: this tests exactly the
behaviour that has been changed, and so was removed
- A couple of other test produce the same errors, just in a different
order.
0 commit comments