Skip to content

Lex lifetimes using emoji and emit appropriate error#153893

Open
estebank wants to merge 1 commit intorust-lang:mainfrom
estebank:emoji-lifetime
Open

Lex lifetimes using emoji and emit appropriate error#153893
estebank wants to merge 1 commit intorust-lang:mainfrom
estebank:emoji-lifetime

Conversation

@estebank
Copy link
Contributor

@estebank estebank commented Mar 15, 2026

Lex and parse emoji in lifetimes, and disallow them in the parser with a hard error. Allow emoji to start a lifetime name even if they are not XID_Start.

error: lifetimes cannot contain emoji
  --> $DIR/emoji-in-lifetime.rs:1:22
   |
LL | fn bad_lifetime_name<'🐛🐛🐛family👨👩👧👦>(
   |                      ^^^^^^^^^^^^^^^^^^^^^

Address #141081 (but we could provide more information in the diagnostic, pointing at the specific chars, providing a link to the reference on identifiers and/or some other extra information).

@rustbot
Copy link
Collaborator

rustbot commented Mar 15, 2026

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 15, 2026

r? @jdonszelmann

rustbot has assigned @jdonszelmann.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 15 candidates

@rust-log-analyzer

This comment has been minimized.

Lex and parse emoji in lifetimes, and disallow them in the parser with a hard error. Allow emoji to start a lifetime name even if they are not XID_Start.

```
error: lifetimes cannot contain emoji
  --> $DIR/emoji-in-lifetime.rs:1:22
   |
LL | fn bad_lifetime_name<'🐛🐛🐛family👨👩👧👦>(
   |                      ^^^^^^^^^^^^^^^^^^^^^
```
@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
    |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `has_emoji`
    |
help: include the missing field in the pattern
    |
258 |                 rustc_lexer::TokenKind::Lifetime { starts_with_number, has_emoji } => {
    |                                                                      +++++++++++
help: if you don't care about this missing field, you can explicitly ignore it
    |
258 |                 rustc_lexer::TokenKind::Lifetime { starts_with_number, has_emoji: _ } => {
    |                                                                      ++++++++++++++
help: or always ignore missing fields here
    |
258 |                 rustc_lexer::TokenKind::Lifetime { starts_with_number, .. } => {
    |                                                                      ++++

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants