Supporting Emoji in identifiers

Have the ability to put emojis in identifiers

fn ๐Ÿ˜ณ() {}

Error:

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

I NEED THIS FEATURE.

1 Like

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

24 Likes

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

https://www.unicode.org/reports/tr31/

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

12 Likes

Maintainability of libraries? Or something else?

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:

    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:

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:

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!

42 Likes

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

10 Likes

This will require us removing this error :sob:

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

You could just allow everything but crab.

2 Likes

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

29 Likes

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

14 Likes

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

Maybe someone could write a Punycode mangler as a proc-macro.

2 Likes

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๏ผš

fn sym!("โ˜…")() {
    let sym!("โ–ก") = 42;
}

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

use paste::paste;

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

prints

100
2 Likes

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 ".:crab:" files to output plain ".rs" sources.

4 Likes

That sounds like a great April Fools PR/RFC: accept lib.๐Ÿฆ€ filenames.

12 Likes

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