about summary refs log tree commit diff
path: root/compiler/rustc_lexer
AgeCommit message (Collapse)AuthorLines
2023-03-09fix(lexer): not skipped whitespace warning for '\x0c'bohan-3/+3
2023-03-03Rustdoc-ify LiteralKind noteest31-5/+7
2023-02-14Update lexer lifetime test许杰友 Jieyou Xu (Joe)-1/+1
2023-02-14Don't recover lifetimes/labels containing emojis as character literals许杰友 Jieyou Xu (Joe)-10/+33
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.
2023-01-17Remove double spaces after dots in commentsMaybe Waffle-2/+2
2022-12-27Recover `fn` keyword as `Fn` trait in boundsMichael Goulet-1/+1
2022-12-12minor code cleanupsMatthias Krüger-2/+1
2022-12-10compiler: remove unnecessary imports and qualified pathsKaDiWa-1/+0
2022-11-29update cpufeatures, swap difference to dissimilarklensy-1/+1
2022-11-24Auto merge of #104507 - WaffleLapkin:asderefsyou, r=wesleywiserbors-4/+2
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")
2022-11-16Use `as_deref` in compiler (but only where it makes sense)Maybe Waffle-4/+2
2022-11-16Use `token::Lit` in `ast::ExprKind::Lit`.Nicholas Nethercote-2/+6
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
2022-11-09Rollup merge of #103919 - nnethercote:unescaping-cleanups, r=matkladDylan DPC-103/+66
Unescaping cleanups Some code improvements, and some error message improvements. Best reviewed one commit at a time. r? ````@matklad````
2022-11-08Simplify `unescape_{char,byte}`.Nicholas Nethercote-17/+9
The `usize` isn't needed in the error case.
2022-11-07Make underscore_literal_suffix a hard error.Nicholas Nethercote-3/+6
It's been a warning for 5.5 years. Time to make it a hard error. Closes #42326.
2022-11-05Rename some `result` variables as `res`, for consistency.Nicholas Nethercote-6/+6
2022-11-05Remove `unescape_byte_literal`.Nicholas Nethercote-21/+7
It's easy to just use `unescape_literal` + `byte_from_char`.
2022-11-04Inline and remove `validate_int_literal`.Nicholas Nethercote-5/+5
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.
2022-11-04Improve comments.Nicholas Nethercote-4/+1
Remove a low-value comment, remove a duplicate comment, and correct a third comment.
2022-11-04Make non-ASCII errors more consistent.Nicholas Nethercote-10/+4
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.
2022-11-03Use `Mode` less.Nicholas Nethercote-24/+22
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`.
2022-11-03Clarify range calculations.Nicholas Nethercote-10/+12
There is some subtlety here.
2022-11-03Rename some variables.Nicholas Nethercote-38/+32
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.
2022-10-26rustc_lexer::TokenKind improve docsTshepang Mbambo-5/+18
2022-09-29Remove from compiler/ cratesreez12g-1/+0
2022-09-28Auto merge of #102302 - nnethercote:more-lexer-improvements, r=matkladbors-35/+34
More lexer improvements A follow-up to #99884. r? `@matklad`
2022-09-28Address review comments.Nicholas Nethercote-2/+4
2022-09-28Small cleanups in unescaping code.Nicholas Nethercote-14/+11
- 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.
2022-09-27Fix an incorrect comment.Nicholas Nethercote-1/+1
If a `\x` escape occurs in a non-byte literals (e.g. char literal, string literal), it must be <= 0xff.
2022-09-26Add `rustc_lexer::TokenKind::Eof`.Nicholas Nethercote-4/+13
For alignment with `rust_ast::TokenKind::Eof`. Plus it's a bit faster, due to less `Option` manipulation in `StringReader::next_token`.
2022-09-26Rename some things.Nicholas Nethercote-18/+18
`Cursor` keeps track of the position within the current token. But it uses confusing names that don't make it clear that the "length consumed" is just within the current token. This commit renames things to make this clearer.
2022-09-26Make `rustc_lexer::cursor::Cursor` public.Nicholas Nethercote-21/+9
`Cursor` is currently hidden, and the main tokenization path uses `rustc_lexer::first_token` which involves constructing a new `Cursor` for every single token, which is weird. Also, `first_token` also can't handle empty input, so callers have to check for that first. This commit makes `Cursor` public, so `StringReader` can contain a `Cursor`, which results in a simpler structure. The commit also changes `StringReader::advance_token` so it returns an `Option<Token>`, simplifying the the empty input case.
2022-09-08remove unnecessary `PartialOrd` and `Ord`Takayuki Maeda-1/+1
2022-08-18Add diagnostic translation lints to crates that don't emit them5225225-0/+2
2022-08-01Shrink `Token`.Nicholas Nethercote-71/+71
From 72 bytes to 12 bytes (on x86-64). There are two parts to this: - Changing various source code offsets from 64-bit to 32-bit. This is not a problem because the rest of rustc also uses 32-bit source code offsets. This means `Token` is no longer `Copy` but this causes no problems. - Removing the `RawStrError` from `LiteralKind`. Raw string literal invalidity is now indicated by a `None` value within `RawStr`/`RawByteStr`, and the new `validate_raw_str` function can be used to re-lex an invalid raw string literal to get the `RawStrError`. There is one very small change in behaviour. Previously, if a raw string literal matched both the `InvalidStarter` and `TooManyHashes` cases, the latter would override the former. This has now changed, because `raw_double_quoted_string` now uses `?` and so returns immediately upon detecting the `InvalidStarter` case. I think this is a slight improvement to report the earlier-detected error, and it explains the change in the `test_too_many_hashes` test. The commit also removes a couple of comments that refer to #77629 and say that the size of these types don't affect performance. These comments are wrong, though the performance effect is small.
2022-08-01Inline `first_token`.Nicholas Nethercote-0/+1
Because it's tiny and hot.
2022-06-28fix typo in commentProloy Mishra-1/+1
2022-03-23Reduce max hash in raw strings from u16 to u8Grisha Vartanyan-11/+11
2022-03-16Add test for >65535 hashes in lexing raw stringGrisha-0/+17
2022-02-24Improve `scan_escape`.Nicholas Nethercote-23/+22
`scan_escape` currently has a fast path (for when the first char isn't '\\') and a slow path. This commit changes `scan_escape` so it only handles the slow path, i.e. the actual escaping code. The fast path is inlined into the two call sites. This change makes the code faster, because there is no function call overhead on the fast path. (`scan_escape` is a big function and doesn't get inlined.) This change also improves readability, because it removes a bunch of mode checks on the the fast paths.
2021-12-03Auto merge of #91393 - Julian-Wollersberger:lexer_optimization, r=petrochenkovbors-25/+28
Optimize `rustc_lexer` The `cursor.first()` method in `rustc_lexer` now calls the `chars.next()` method instead of `chars.nth_char(0)`. This allows LLVM to optimize the code better. The biggest win is that `eat_while()` is now fully inlined and generates better assembly. This improves the lexer's performance by 35% in a micro-benchmark I made (Lexing all 18MB of code in the compiler directory). But lexing is only a small part of the overall compilation time, so I don't know how significant it is. Big thanks to criterion and `cargo asm`.
2021-12-01Replace `nth_char(0)` with `next()` in `cursor.first()`Julian Wollersberger-25/+28
and optimize the iterator returned by `tokenize(). This improves lexer performance by 35%
2021-11-23udpate comment to be more accurateEsteban Kuber-2/+1
2021-11-23Tokenize emoji as if they were valid indentifiersEsteban Kuber-0/+26
In the lexer, consider emojis to be valid identifiers and reject them later to avoid knock down parse errors.
2021-11-06use matches!() macro in more placesMatthias Krüger-5/+4
2021-10-15Revert "Auto merge of #89709 - clemenswasser:apply_clippy_suggestions_2, ↵Matthias Krüger-5/+6
r=petrochenkov" The PR had some unforseen perf regressions that are not as easy to find. Revert the PR for now. This reverts commit 6ae8912a3e7d2c4c775024f58a7ba4b1aedc4073, reversing changes made to 86d6d2b7389fe1b339402c1798edae8b695fc9ef.
2021-10-10Apply clippy suggestionsClemens Wasser-6/+5
2021-09-20Migrate to 2021Mark Rousskov-1/+1
2021-08-22Fix more “a”/“an” typosFrank Steffahn-1/+1
2021-08-11Renamed variable str -> tail for clarityAnton Golov-5/+5