| Age | Commit message (Collapse) | Author | Lines |
|
`unescape_raw_str_or_raw_byte_str` only does checking, no unescaping.
And it also now handles C string literals.
`unescape_raw_str` is used for all the non-raw strings.
|
|
Some cases are unreachable.
|
|
- Add `use Mode::*` to avoid all the qualifiers.
- Reorder the variants. The existing order makes no particular sense,
which has bugged me for some time. I've chosen an order that makes
sense to me.
|
|
|
|
These don't really make sense since C string literals were added. This
commit removes them in favour for `mode: Mode` args. `ascii_check` still
has a `characters_should_be_ascii: bool` arg.
Also, `characters_should_be_ascii` is renamed to be shorter.
|
|
The fallback `_` case works for these chars, no need to treat them
specially.
|
|
|
|
|
|
Raw strings (of all kinds) don't support escapes, so this function
should never be called on them.
|
|
|
|
|
|
Reimplement C-str literals
This reverts #113334, cc `@fmease.`
While converting lexer tokens to ast Tokens in `rustc_parse`, we check the edition of the span of the token. If the edition < 2021, we split the token into two, one being the identifier and other being the str literal.
|
|
comparison_to_empty
iter_nth_zero
for_kv_map
manual_next_back
redundant_pattern
|
|
|
|
|
|
After seeing a `0`, if it's followed by any of `[0-9]`, `_`, `.`, `e`,
or `E`, we consume all the digits. But in the `.`, `e` and `E` cases
this is pointless because we know there aren't any digits.
|
|
A tiny bit of repetition makes this easier to read, and avoids a test on
the "Not a base prefix" match arm.
|
|
|
|
|
|
|
|
|
|
Reverts PR #108031
Fixes (doesnt close until beta backported) #109746
This reverts commit e3f9db5fc319c6d8eee5d47d216ea6a426070c41.
This reverts commit 98b82aedba3f3f581e89df54352914b27f42c6f7.
This reverts commit 380fa264132ad481e73cbbf0f3a0feefd99a1d78.
|
|
|
|
|
|
|
|
Note that at the time of this commit, `unic-emoji-char` seems to have
data tables only up to Unicode 5.0, but Unicode is already newer than
this.
A newer emoji such as `🥺` will not be recognized as an emoji
but older emojis such as `🐱` will.
|
|
|
|
|
|
|
|
|
|
Use `as_deref` in compiler (but only where it makes sense)
This simplifies some code :3
(there are some changes that are not exacly `as_deref`, but more like "clever `Option`/`Result` method use")
|
|
|
|
Instead of `ast::Lit`.
Literal lowering now happens at two different times. Expression literals
are lowered when HIR is crated. Attribute literals are lowered during
parsing.
This commit changes the language very slightly. Some programs that used
to not compile now will compile. This is because some invalid literals
that are removed by `cfg` or attribute macros will no longer trigger
errors. See this comment for more details:
https://github.com/rust-lang/rust/pull/102944#issuecomment-1277476773
|
|
Unescaping cleanups
Some code improvements, and some error message improvements.
Best reviewed one commit at a time.
r? ````@matklad````
|
|
The `usize` isn't needed in the error case.
|
|
It's been a warning for 5.5 years. Time to make it a hard error.
Closes #42326.
|
|
|
|
It's easy to just use `unescape_literal` + `byte_from_char`.
|
|
It has a single callsite, and is fairly small. The `Float` match arm
already has base-specific checking inline, so this makes things more
consistent.
|
|
Remove a low-value comment, remove a duplicate comment, and correct a
third comment.
|
|
There are three kinds of "byte" literals: byte literals, byte string
literals, and raw byte string literals. None are allowed to have
non-ASCII chars in them.
Two `EscapeError` variants exist for when that constraint is violated.
- `NonAsciiCharInByte`: used for byte literals and byte string literals.
- `NonAsciiCharInByteString`: used for raw byte string literals.
As a result, the messages for raw byte string literals use different
wording, without good reason. Also, byte string literals are incorrectly
described as "byte constants" in some error messages.
This commit eliminates `NonAsciiCharInByteString` so the three cases are
handled similarly, and described correctly. The `mode` is enough to
distinguish them.
Note: Some existing error messages mention "byte constants" and some
mention "byte literals". I went with the latter here, because it's a
more correct name, as used by the Reference.
|
|
It's passed to numerous places where we just need an `is_byte` bool.
Passing the bool avoids the need for some assertions.
Also rename `is_bytes()` as `is_byte()`, to better match `Mode::Byte`,
`Mode::ByteStr`, and `Mode::RawByteStr`.
|
|
There is some subtlety here.
|
|
These have been bugging me for a while.
- `literal_text`: `src` is also used and is shorter and better.
- `first_char`: used even when "first" doesn't make sense; `c` is
shorter and better.
- `curr`: `c` is shorter and better.
- `unescaped_char`: `result` is also used and is shorter and better.
- `second_char`: these have a single use and can be elided.
|
|
|
|
More lexer improvements
A follow-up to #99884.
r? `@matklad`
|
|
|
|
- Rename `unescape_raw_str_or_raw_byte_str` as
`unescape_raw_str_or_byte_str`, which is more accurate.
- Remove the unused `Mode::in_single_quotes` method.
- Make some assertions more precise, and add a missing one to
`unescape_char_or_byte`.
- Change all the assertions to `debug_assert!`, because this code is
reasonably hot, and the assertions aren't required for memory safety,
and any violations are likely to be sufficiently obvious that normal
tests will trigger them.
|
|
If a `\x` escape occurs in a non-byte literals (e.g. char literal,
string literal), it must be <= 0xff.
|
|
For alignment with `rust_ast::TokenKind::Eof`. Plus it's a bit faster,
due to less `Option` manipulation in `StringReader::next_token`.
|