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 mostly called when
lowering AST to HIR, but also in a few other places during expansion.
This one actually constructs the unescaped string. It also has error
checking code, but that code handling the error cases is actually dead
(and has several bugs) because the check during lexing catches all
errors!
This commit removes the checking during lexing, and fixes up
`LitKind::from_token_lit` so it properly does both checking and
construction. This is a language change: some programs now compile that
previously did not. For example, it is now possible for macros to be
passed "invalid" string literals like "\a\b\c". This is a continuation
of a trend of delaying semantic error checking of literals to after
expansion, e.g. #102944 did this for some cases for numeric literals,
and the detection of NUL chars in C string literals is already delayed
in this way.
XXX: have Session::report_lit_errors?
XXX: have LitKind::from_token_lit so you don't need the .0?
Things to note:
- `LitError` has a new `EscapeError` variant.
- `LitKind::from_token_lit`'s return value changed, to produce multiple
errors/warnings, and also to handle lexer warnings. This latter case
is annoying but necessary to preserve existing warning behaviour.
- `report_lit_error` becomes `report_lit_errors`, in order to handle
multiple errors in a single string literal.
Notes about test changes:
- `tests/rustdoc-ui/ignore-block-help.rs`: this relies on a parsing
error occurring. The error present was an unescaping error, which is
now delayed to after parsing. So the commit changes it to an
"unterminated character literal" error which continues to occurs
during parsing.
- 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 #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
XXX: insert a new test covering more of that
- A couple of other test produce the same errors, just in a different
order.
0 commit comments