# Supporting Emoji in identifiers

**URL:** https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838
**Category:** language design
**Created:** [June 17, 2022, 11:21pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838 "2022-06-17T23:21:00Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![lemonjamesd](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lemonjamesd/32/11180_2.png) [@lemonjamesd](https://internals.rust-lang.org/u/lemonjamesd)
#### Post date: [June 17, 2022, 11:21pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/1 "2022-06-17T23:21:00Z")

</div>

Have the ability to put emojis in identifiers

```nohighlight
fn 😳() {}

```

Error:

```nohighlight
error: identifiers cannot contain emoji: `😳`
 --> src/main.rs:1:14
  |
1 | macro_rules! 😳 {
  | ^^
...
7 | fn 😳() {}
  | ^^

```

**I NEED THIS FEATURE.**

---

<div class="post-metadata">

### Author: ![josh](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/josh/32/5934_2.png) [@josh](https://internals.rust-lang.org/u/josh)
#### Post date: [June 17, 2022, 11:33pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/2 "2022-06-17T23:33:51Z")

</div>

We did consider this when considering Unicode identifiers, and intentionally decided against it. While it would be entertaining, it would also sacrifice maintainability. Sorry. 🙂

---

<div class="post-metadata">

### Author: ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)
#### Post date: [June 17, 2022, 11:41pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/3 "2022-06-17T23:41:20Z")

</div>

In case you're not aware, Rust follows the Unicode standard for `XID_Start` and `XID_Continue`:

[https://www.unicode.org/reports/tr31/](https://www.unicode.org/reports/tr31/)

... with the sole addition of `_` as a start character.

---

<div class="post-metadata">

### Author: ![lemonjamesd](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lemonjamesd/32/11180_2.png) [@lemonjamesd](https://internals.rust-lang.org/u/lemonjamesd)
#### Post date: [June 17, 2022, 11:44pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/4 "2022-06-17T23:44:45Z")

</div>

Maintainability of libraries? Or something else?

---

<div class="post-metadata">

### Author: ![afetisov](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/afetisov/32/8508_2.png) [@afetisov](https://internals.rust-lang.org/u/afetisov)
#### Post date: [June 18, 2022, 1:15am UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/5 "2022-06-18T01:15:51Z")

</div>

It is indeed most unfortunate that legacy standards such as `XID_Start` and `XID_Continue` unicode properties prevent the use of perfectly cromulent and inclusive symbols such as emojies. Fortunately, at least we can get a partial workaround using even more ancient text standards, e.g. egyptian hieroglyphs. This is valid Rust code:

```rust
    let 𓀀 = 1u32;
    let 𓆣 = 2u32;
    let 𓀬 = 3u32;
    let 𓆸 = vec![𓀀, 𓆣, 𓀬];
    let 𓀫 = 𓆸.into_boxed_slice();
    let 𓀭 = 𓀫.len();

```

You just need to disable pesky `uncommon_codepoints` lints.

If you think that all the good stuff was in the past and they just don't make languages like the old ones anymore (just look at chinese, gosh! that's what I call a bloated language!), you can use the simple and natural cuniform from a more civilized age:

```rust
let 𒆩 = 1u32;
let 𒆯 = 2u32;
let 𒀀 = 3u32;
let 𒅄 = vec![𒆩, 𒆯, 𒀀];
let 𒆳 = 𒅄.into_boxed_slice();
let 𒐫 = 𒆳.len();    

```

Even a child can write that one! And they said COBOL was archaic 𓃜 𓆦

The learned ones may prefer something more exquisite, with subtle artistic expression in the stroke of every symbol:

```rust
let ꦋ = 1u32;
let ꦯ෯ = 2u32;
let ꧮ = 3u32;
let ꩶ = vec![ꦋ, ꦯ෯, ꧮ];
let ꬤ = ꩶ.into_boxed_slice();
let ꘚ = ꬤ.len();

```

Ah, Unicode! You're a real treasure trꙮve of beautiful artisanal code!

---

<div class="post-metadata">

### Author: ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)
#### Post date: [June 18, 2022, 1:45am UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/6 "2022-06-18T01:45:18Z")

</div>

It seems I don't have the fonts for most of your symbols... 😅

---

<div class="post-metadata">

### Author: ![chrefr](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@chrefr](https://internals.rust-lang.org/u/chrefr)
#### Post date: [June 18, 2022, 11:52pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/7 "2022-06-18T23:52:59Z")

</div>

This will require us removing [this error](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=cf826cb5d6ac4ebc2bef6317f4231d3d) 😭

```rust
error: Ferris cannot be used as an identifier
 --> src/main.rs:2:9
  |
2 | let 🦀 = 0;
  | ^^ help: try using their name instead: `ferris`

```

---

<div class="post-metadata">

### Author: ![lemonjamesd](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/lemonjamesd/32/11180_2.png) [@lemonjamesd](https://internals.rust-lang.org/u/lemonjamesd)
#### Post date: [June 19, 2022, 11:34am UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/8 "2022-06-19T11:34:11Z")

</div>

You could just allow everything but crab.

---

<div class="post-metadata">

### Author: ![toc](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/toc/32/6692_2.png) [@toc](https://internals.rust-lang.org/u/toc)
#### Post date: [June 19, 2022, 6:00pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/9 "2022-06-19T18:00:26Z")

</div>

It wouldn't work. Long term all emoji will converge to crab forms regardless.

---

<div class="post-metadata">

### Author: ![CAD97](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cad97/32/3460_2.png) [@CAD97](https://internals.rust-lang.org/u/CAD97)
#### Post date: [June 19, 2022, 8:59pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/10 "2022-06-19T20:59:33Z")

</div>

Someone should make an emoji font where all of the people emoji are crabs (and maybe other crustaceans via skin tone selectors?)

---

<div class="post-metadata">

### Author: ![tech6hutch](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tech6hutch/32/6344_2.png) [@tech6hutch](https://internals.rust-lang.org/u/tech6hutch)
#### Post date: [June 27, 2022, 8:29pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/11 "2022-06-27T20:29:09Z")

</div>

Ok but could we maybe have this behind a permanently nightly feature gate? Please? 🥺 🥺 🥺

---

<div class="post-metadata">

### Author: ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)
#### Post date: [June 27, 2022, 10:05pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/12 "2022-06-27T22:05:24Z")

</div>

Maybe someone could write a [Punycode](https://en.wikipedia.org/wiki/Punycode) mangler as a proc-macro.

---

<div class="post-metadata">

### Author: ![crlf0710](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/crlf0710/32/1987_2.png) [@crlf0710](https://internals.rust-lang.org/u/crlf0710)
#### Post date: [July 2, 2022, 2:44am UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/13 "2022-07-02T02:44:22Z")

</div>

This won't work currently. We'll need item name position macro and pattern position macros available before we get something like this to work：

```rust
fn sym!("★")() {
    let sym!("□") = 42;
}

```

---

<div class="post-metadata">

### Author: ![matt1985](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matt1985/32/4772_2.png) [@matt1985](https://internals.rust-lang.org/u/matt1985)
#### Post date: [July 2, 2022, 3:23am UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/14 "2022-07-02T03:23:54Z")

</div>

Regarding that code, while the function name isn't a valid place for invoking a proc macro, patterns (such as in `let sym!("□") =`) _are_ a valid place to call one.

[https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1b7e42be0b334d08fdd1edc8df39f498](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=1b7e42be0b334d08fdd1edc8df39f498)

```rust
use paste::paste;

fn main(){
    let paste!([<foo bar>]) = 100;
    println!("{foobar}");
}

```

prints

```rust
100

```

---

<div class="post-metadata">

### Author: ![cuviper](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/cuviper/32/1897_2.png) [@cuviper](https://internals.rust-lang.org/u/cuviper)
#### Post date: [July 2, 2022, 3:50pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/15 "2022-07-02T15:50:34Z")

</div>

While I was kidding, I was imagining it as an attribute macro that operates on an entire function or block to replace the identifiers within. I guess the complier would have to be able to tokenize that first though, so that won't really work.

Maybe instead, use a true preprocessor on ".🦀" files to output plain ".rs" sources.

---

<div class="post-metadata">

### Author: ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)
#### Post date: [July 2, 2022, 11:10pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/16 "2022-07-02T23:10:46Z")

</div>

> [@cuviper](#):
>
> ".🦀"

That sounds like a great April Fools PR/RFC: accept `lib.🦀` filenames.

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)
#### Post date: [September 30, 2022, 11:11pm UTC](https://internals.rust-lang.org/t/supporting-emoji-in-identifiers/16838/17 "2022-09-30T23:11:15Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
