about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-11-25 08:16:08 +0000
committerbors <bors@rust-lang.org>2021-11-25 08:16:08 +0000
commit23a436606b118bd2fbb12f64fce21e7f9d355349 (patch)
treef7cdcfcb705dc416fd967deb4e89ad3184f282c4 /src
parentc6eda7d8a7af3ef51311d3106874a7d8de994edc (diff)
parentd92916439c372967e4c12b7ece3c8d7e860a8777 (diff)
Auto merge of #88781 - estebank:emoji-idents, r=oli-obk
Tokenize emoji as if they were valid identifiers

In the lexer, consider emojis to be valid identifiers and reject
them later to avoid knock down parse errors.

Partially address #86102.
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/html/highlight.rs2
-rw-r--r--src/test/ui/parser/emoji-identifiers.rs16
-rw-r--r--src/test/ui/parser/emoji-identifiers.stderr83
m---------src/tools/cargo0
-rw-r--r--src/tools/tidy/src/deps.rs11
5 files changed, 108 insertions, 4 deletions
diff --git a/src/librustdoc/html/highlight.rs b/src/librustdoc/html/highlight.rs
index e177a113036..688860f94e1 100644
--- a/src/librustdoc/html/highlight.rs
+++ b/src/librustdoc/html/highlight.rs
@@ -632,7 +632,7 @@ impl<'a> Classifier<'a> {
                 },
                 Some(c) => c,
             },
-            TokenKind::RawIdent | TokenKind::UnknownPrefix => {
+            TokenKind::RawIdent | TokenKind::UnknownPrefix | TokenKind::InvalidIdent => {
                 Class::Ident(self.new_span(before, text))
             }
             TokenKind::Lifetime { .. } => Class::Lifetime,
diff --git a/src/test/ui/parser/emoji-identifiers.rs b/src/test/ui/parser/emoji-identifiers.rs
new file mode 100644
index 00000000000..ef18939bbb8
--- /dev/null
+++ b/src/test/ui/parser/emoji-identifiers.rs
@@ -0,0 +1,16 @@
+struct ABig๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘งFamily; //~ ERROR identifiers cannot contain emoji
+struct ๐Ÿ‘€; //~ ERROR identifiers cannot contain emoji
+impl ๐Ÿ‘€ {
+    fn full_of_โœจ() -> ๐Ÿ‘€ { //~ ERROR identifiers cannot contain emoji
+        ๐Ÿ‘€
+    }
+}
+fn i_like_to_๐Ÿ˜…_a_lot() -> ๐Ÿ‘€ { //~ ERROR identifiers cannot contain emoji
+    ๐Ÿ‘€::full_ofโœจ() //~ ERROR no function or associated item named `full_ofโœจ` found for struct `๐Ÿ‘€`
+    //~^ ERROR identifiers cannot contain emoji
+}
+fn main() {
+    let _ = i_like_to_๐Ÿ˜„_a_lot() โž– 4; //~ ERROR cannot find function `i_like_to_๐Ÿ˜„_a_lot` in this scope
+    //~^ ERROR identifiers cannot contain emoji
+    //~| ERROR unknown start of token: \u{2796}
+}
diff --git a/src/test/ui/parser/emoji-identifiers.stderr b/src/test/ui/parser/emoji-identifiers.stderr
new file mode 100644
index 00000000000..5f9263c4c13
--- /dev/null
+++ b/src/test/ui/parser/emoji-identifiers.stderr
@@ -0,0 +1,83 @@
+error: unknown start of token: \u{2796}
+  --> $DIR/emoji-identifiers.rs:13:33
+   |
+LL |     let _ = i_like_to_๐Ÿ˜„_a_lot() โž– 4;
+   |                                  ^^
+   |
+help: Unicode character 'โž–' (Heavy Minus Sign) looks like '-' (Minus/Hyphen), but it is not
+   |
+LL |     let _ = i_like_to_๐Ÿ˜„_a_lot() - 4;
+   |                                  ~
+
+error[E0425]: cannot find function `i_like_to_๐Ÿ˜„_a_lot` in this scope
+  --> $DIR/emoji-identifiers.rs:13:13
+   |
+LL | fn i_like_to_๐Ÿ˜…_a_lot() -> ๐Ÿ‘€ {
+   | ----------------------------- similarly named function `i_like_to_๐Ÿ˜…_a_lot` defined here
+...
+LL |     let _ = i_like_to_๐Ÿ˜„_a_lot() โž– 4;
+   |             ^^^^^^^^^^^^^^^^^^ help: a function with a similar name exists: `i_like_to_๐Ÿ˜…_a_lot`
+
+error: identifiers cannot contain emoji: `ABig๐Ÿ‘ฉ๐Ÿ‘ฉ๐Ÿ‘ง๐Ÿ‘งFamily`
+  --> $DIR/emoji-identifiers.rs:1:8
+   |
+LL | struct ABig๐Ÿ‘ฉ๐Ÿ‘ฉ๐Ÿ‘ง๐Ÿ‘งFamily;
+   |        ^^^^^^^^^^^^^^^^^^
+
+error: identifiers cannot contain emoji: `๐Ÿ‘€`
+  --> $DIR/emoji-identifiers.rs:2:8
+   |
+LL | struct ๐Ÿ‘€;
+   |        ^^
+LL | impl ๐Ÿ‘€ {
+   |      ^^
+LL |     fn full_of_โœจ() -> ๐Ÿ‘€ {
+   |                        ^^
+LL |         ๐Ÿ‘€
+   |         ^^
+...
+LL | fn i_like_to_๐Ÿ˜…_a_lot() -> ๐Ÿ‘€ {
+   |                            ^^
+LL |     ๐Ÿ‘€::full_ofโœจ()
+   |     ^^
+
+error: identifiers cannot contain emoji: `full_of_โœจ`
+  --> $DIR/emoji-identifiers.rs:4:8
+   |
+LL |     fn full_of_โœจ() -> ๐Ÿ‘€ {
+   |        ^^^^^^^^^^
+
+error: identifiers cannot contain emoji: `i_like_to_๐Ÿ˜…_a_lot`
+  --> $DIR/emoji-identifiers.rs:8:4
+   |
+LL | fn i_like_to_๐Ÿ˜…_a_lot() -> ๐Ÿ‘€ {
+   |    ^^^^^^^^^^^^^^^^^^
+
+error: identifiers cannot contain emoji: `full_ofโœจ`
+  --> $DIR/emoji-identifiers.rs:9:8
+   |
+LL |     ๐Ÿ‘€::full_ofโœจ()
+   |         ^^^^^^^^^
+
+error: identifiers cannot contain emoji: `i_like_to_๐Ÿ˜„_a_lot`
+  --> $DIR/emoji-identifiers.rs:13:13
+   |
+LL |     let _ = i_like_to_๐Ÿ˜„_a_lot() โž– 4;
+   |             ^^^^^^^^^^^^^^^^^^
+
+error[E0599]: no function or associated item named `full_ofโœจ` found for struct `๐Ÿ‘€` in the current scope
+  --> $DIR/emoji-identifiers.rs:9:8
+   |
+LL | struct ๐Ÿ‘€;
+   | ---------- function or associated item `full_ofโœจ` not found for this
+...
+LL |     ๐Ÿ‘€::full_ofโœจ()
+   |         ^^^^^^^^^
+   |         |
+   |         function or associated item not found in `๐Ÿ‘€`
+   |         help: there is an associated function with a similar name: `full_of_โœจ`
+
+error: aborting due to 9 previous errors
+
+Some errors have detailed explanations: E0425, E0599.
+For more information about an error, try `rustc --explain E0425`.
diff --git a/src/tools/cargo b/src/tools/cargo
-Subproject e1fb17631eb1b3665cdbe45b1c186111577ef51
+Subproject 7f08ace4f1305de7f3b1b0e2f765911957226bd
diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs
index c1719a9ffe8..bc33284f31e 100644
--- a/src/tools/tidy/src/deps.rs
+++ b/src/tools/tidy/src/deps.rs
@@ -82,8 +82,8 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
     "bitflags",
     "block-buffer",
     "block-padding",
-    "byteorder",
     "byte-tools",
+    "byteorder",
     "cc",
     "cfg-if",
     "chalk-derive",
@@ -140,9 +140,9 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
     "memmap2",
     "memoffset",
     "miniz_oxide",
-    "num_cpus",
     "num-integer",
     "num-traits",
+    "num_cpus",
     "object",
     "odht",
     "once_cell",
@@ -190,8 +190,8 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
     "serde_json",
     "sha-1",
     "sha2",
-    "smallvec",
     "sharded-slab",
+    "smallvec",
     "snap",
     "stable_deref_trait",
     "stacker",
@@ -211,6 +211,11 @@ const PERMITTED_DEPENDENCIES: &[&str] = &[
     "tracing-subscriber",
     "tracing-tree",
     "typenum",
+    "unic-char-property",
+    "unic-char-range",
+    "unic-common",
+    "unic-emoji-char",
+    "unic-ucd-version",
     "unicode-normalization",
     "unicode-script",
     "unicode-security",