about summary refs log tree commit diff
path: root/compiler/rustc_lexer/src
AgeCommit message (Collapse)AuthorLines
2025-09-22Fix a crash/mislex when more than one frontmatter closing possibility is ↵Alex-1/+3
considered
2025-09-01fix(lexer): Only allow horizontal whitespace in frontmatterEd Page-3/+18
In writing up the reference for frontmatter, I realized that we probably shouldn't be accepting Unicode Line Ending characters between the code fence and infostring or trailing after the infostring or a code fence. In digging into the unicode specification we use for Whitespace, it divides it up into categories, so I'm deferring to what it says for horizontal whitespace for what should be used within a line. Note, I am leaving out support for Unicde Default Ignorable characters. I figure that can be discussed outside of this change within the reference and tracking issue.
2025-09-01docs(lexer): Organize and document whitespace by Pattern_White_SpaceEd Page-12/+10
2025-08-28fix(lexer): Don't require frontmatters to be escaped with indented fencesEd Page-21/+13
The RFC only limits hyphens at the beginning of lines and not if they are indented or embedded in other content. Sticking to that approach was confirmed by the T-lang liason at https://github.com/rust-lang/rust/issues/141367#issuecomment-3202217544 There is a regression in error message quality which I'm leaving for someone if they feel this needs improving.
2025-08-22fix(lexer): Allow '-' in the infostring continue setEd Page-2/+2
This more closely matches the RFC and what our T-lang contact has asked for, see https://github.com/rust-lang/rust/issues/136889#issuecomment-3212715312
2025-07-10test(lexer): Add frontmatter unit testEd Page-2/+84
2025-07-09feat(lexer): Allow including frontmatter with 'tokenize'Ed Page-11/+21
2025-07-03setup CI and tidy to use typos for spellchecking and fix few typosklensy-1/+1
2025-06-06rustc_lexer: typo fix + small cleanupsMarijn Schouten-10/+8
2025-06-04Fix parsing of frontmatters with inner hyphensMatthew Jasper-1/+3
2025-05-05Implement RFC 3503: frontmattersDeadbeef-9/+162
Supercedes #137193
2025-04-04Replace `rustc_lexer/unescape` with `rustc-literal-escaper` crateGuillaume Gomez-725/+0
2025-03-18Revert "Rollup merge of #136355 - ↵Ralf Jung-3/+725
GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu" This reverts commit 08dfbf49e30d917c89e49eb14cb3f1e8b8a1c9ef, reversing changes made to 10bcdad7df0de3cfb95c7bdb7b16908e73cafc09.
2025-03-17Rollup merge of #136355 - ↵Jacob Pratt-725/+3
GuillaumeGomez:proc-macro_add_value_retrieval_methods, r=Amanieu Add `*_value` methods to proc_macro lib This is the implementation of https://github.com/rust-lang/libs-team/issues/459. It allows to get the actual value (unescaped) of the different string literals. Part of https://github.com/rust-lang/rust/issues/136652. r? libs-api
2025-03-11Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
It's no longer necessary now that `-Wunreachable_pub` is being passed.
2025-03-10Revert "Use workspace lints for crates in `compiler/` #138084"许杰友 Jieyou Xu (Joe)-0/+1
Revert <https://github.com/rust-lang/rust/pull/138084> to buy time to consider options that avoids breaking downstream usages of cargo on distributed `rustc-src` artifacts, where such cargo invocations fail due to inability to inherit `lints` from workspace root manifest's `workspace.lints` (this is only valid for the source rust-lang/rust workspace, but not really the distributed `rustc-src` artifacts). This breakage was reported in <https://github.com/rust-lang/rust/issues/138304>. This reverts commit 48caf81484b50dca5a5cebb614899a3df81ca898, reversing changes made to c6662879b27f5161e95f39395e3c9513a7b97028.
2025-03-08Remove `#![warn(unreachable_pub)]` from all `compiler/` crates.Nicholas Nethercote-1/+0
(Except for `rustc_codegen_cranelift`.) It's no longer necessary now that `unreachable_pub` is in the workspace lints.
2025-02-22Greatly simplify lifetime captures in edition 2024Michael Goulet-1/+1
2025-02-10Reexport `literal-escaper` from `rustc_lexer` to allow rust-analyzer to compileGuillaume Gomez-0/+3
2025-02-10Extract `unescape` from `rustc_lexer` into its own crateGuillaume Gomez-725/+0
2025-02-08Rustfmtbjorn3-16/+34
2025-02-05implement `eat_until` leveraging memchr in lexergvozdvmozgu-2/+9
2024-12-09Add test to check unicode identifier versionEric Huss-0/+1
2024-12-01Revert "Reject raw lifetime followed by \' as well"Michael Goulet-11/+1
This reverts commit 1990f1560801ca3f9e6a3286e58204aa329ee037.
2024-11-25Clean up `c_or_byte_string`.Nicholas Nethercote-4/+4
- Rename a misleading local `mk_kind` as `single_quoted`. - Use `fn` for all three arguments, for consistency.
2024-11-25Improve `strip_shebang` testing.Nicholas Nethercote-41/+31
It's currently a bit ad hoc. This commit makes it more methodical, with pairs of match/no-match tests for all the relevant cases.
2024-11-19Remove `TokenKind::InvalidPrefix`.Nicholas Nethercote-13/+8
It was added in #123752 to handle some cases involving emoji, but it isn't necessary because it's always treated the same as `TokenKind::InvalidIdent`. This commit removes it, which makes things a little simpler.
2024-11-19Improve `TokenKind` comments.Nicholas Nethercote-41/+39
- Improve wording. - Use backticks consistently for examples.
2024-11-19Improve `fake_ident_or_unknown_prefix`.Nicholas Nethercote-6/+5
- Rename it as `invalid_ident_or_prefix`, which matches the possible outputs (`InvalidIdent` or `InvalidPrefix`). - Use the local wrapper for `is_xid_continue`, for consistency. - Make it clear what `\u{200d}` means.
2024-10-30Reject raw lifetime followed by \' as wellMichael Goulet-1/+11
2024-10-08Reserve guarded string literals (RFC 3593)Peter Jaszkowiak-8/+85
2024-09-22Reformat using the new identifier sorting from rustfmtMichael Goulet-35/+17
2024-09-06Add initial support for raw lifetimesMichael Goulet-1/+12
2024-09-06Format lexerMichael Goulet-1/+1
2024-09-06Reserve prefix lifetimes tooMichael Goulet-9/+17
2024-08-27Add `warn(unreachable_pub)` to `rustc_lexer`.Nicholas Nethercote-0/+1
2024-07-29Reformat `use` declarations.Nicholas Nethercote-4/+4
The previous commit updated `rustfmt.toml` appropriately. This commit is the outcome of running `x fmt --all` with the new formatting options.
2024-06-12Use `tidy` to sort crate attributes for all compiler crates.Nicholas Nethercote-0/+2
We already do this for a number of crates, e.g. `rustc_middle`, `rustc_span`, `rustc_metadata`, `rustc_span`, `rustc_errors`. For the ones we don't, in many cases the attributes are a mess. - There is no consistency about order of attribute kinds (e.g. `allow`/`deny`/`feature`). - Within attribute kind groups (e.g. the `feature` attributes), sometimes the order is alphabetical, and sometimes there is no particular order. - Sometimes the attributes of a particular kind aren't even grouped all together, e.g. there might be a `feature`, then an `allow`, then another `feature`. This commit extends the existing sorting to all compiler crates, increasing consistency. If any new attribute line is added there is now only one place it can go -- no need for arbitrary decisions. Exceptions: - `rustc_log`, `rustc_next_trait_solver` and `rustc_type_ir_macros`, because they have no crate attributes. - `rustc_codegen_gcc`, because it's quasi-external to rustc (e.g. it's ignored in `rustfmt.toml`).
2024-04-24Improved the compiler code with clippyMichael Scholten-5/+5
2024-04-10Properly handle emojis as literal prefix in macrosEsteban Küber-1/+5
Do not accept the following ```rust macro_rules! lexes {($($_:tt)*) => {}} lexes!(🐛"foo"); ``` Before, invalid emoji identifiers were gated during parsing instead of lexing in all cases, but this didn't account for macro expansion of literal prefixes. Fix #123696.
2024-03-17Silence redundant error on char literal that was meant to be a string in ↵Esteban Küber-0/+9
2021 edition
2024-03-17Handle str literals written with `'` lexed as lifetimeEsteban Küber-1/+1
Given `'hello world'` and `'1 str', provide a structured suggestion for a valid string literal: ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-3.rs:2:26 | LL | println!('hello world'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("hello world"); | ~ ~ ``` ``` error[E0762]: unterminated character literal --> $DIR/lex-bad-str-literal-as-char-1.rs:2:20 | LL | println!('1 + 1'); | ^^^^ | help: if you meant to write a `str` literal, use double quotes | LL | println!("1 + 1"); | ~ ~ ``` Fix #119685.
2024-02-06Invert diagnostic lints.Nicholas Nethercote-2/+1
That is, change `diagnostic_outside_of_impl` and `untranslatable_diagnostic` from `allow` to `deny`, because more than half of the compiler has be converted to use translated diagnostics. This commit removes more `deny` attributes than it adds `allow` attributes, which proves that this change is warranted.
2024-01-25Use `unescape_unicode` for raw C string literals.Nicholas Nethercote-19/+14
They can't contain `\x` escapes, which means they can't contain high bytes, which means we can used `unescape_unicode` instead of `unescape_mixed` to unescape them. This avoids unnecessary used of `MixedUnit`.
2024-01-25Rename the unescaping functions.Nicholas Nethercote-9/+13
`unescape_literal` becomes `unescape_unicode`, and `unescape_c_string` becomes `unescape_mixed`. Because rfc3349 will mean that C string literals will no longer be the only mixed utf8 literals.
2024-01-25Rename and invert sense of `Mode` predicates.Nicholas Nethercote-32/+24
I find it easier if they describe what's allowed, rather than what's forbidden. Also, consistent naming makes them easier to understand.
2024-01-25Rework `CStrUnit`.Nicholas Nethercote-34/+45
- Rename it as `MixedUnit`, because it will soon be used in more than just C string literals. - Change the `Byte` variant to `HighByte` and use it only for `\x80`..`\xff` cases. This fixes the old inexactness where ASCII chars could be encoded with either `Byte` or `Char`. - Add useful comments. - Remove `is_ascii`, in favour of `u8::is_ascii`.
2024-01-25Use `from` instead of `into` in unescaping code.Nicholas Nethercote-4/+4
The `T` type in these functions took me some time to understand, and I find the explicit `T` in the use of `from` makes the code easier to read, as does the `u8` annotation in `scan_escape`.
2024-01-22Rollup merge of #118639 - fmease:deny-features-in-stable-rustc-crates, ↵Matthias Krüger-2/+3
r=WaffleLapkin Undeprecate lint `unstable_features` and make use of it in the compiler See also #117937. r? compiler
2024-01-12Detect `NulInCStr` error earlier.Nicholas Nethercote-2/+15
By making it an `EscapeError` instead of a `LitError`. This makes it like the other errors produced when checking string literals contents, e.g. for invalid escape sequences or bare CR chars. NOTE: this means these errors are issued earlier, before expansion, which changes behaviour. It will be possible to move the check back to the later point if desired. If that happens, it's likely that all the string literal contents checks will be delayed together. One nice thing about this: the old approach had some code in `report_lit_error` to calculate the span of the nul char from a range. This code used a hardwired `+2` to account for the `c"` at the start of a C string literal, but this should have changed to a `+3` for raw C string literals to account for the `cr"`, which meant that the caret in `cr"` nul error messages was one short of where it should have been. The new approach doesn't need any of this and avoids the off-by-one error.