You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Improve diagnostics for character literals containing multiple codepoints #88684
A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
I tried to compile the following code (playground):
constSPADE:char = '♠️';
For the avoidance of doubt, ♠️ is U+2660. I expected the code to compile—but instead, the literal is rejected:
error: character literal may only contain one codepoint
--> src/lib.rs:1:21
|
1 | const SPADE: char = '♠️';
| ^^^
|
help: if you meant to write a `str` literal, use double quotes
|
1 | const SPADE: char = "♠️";
| ^^^
The spade "character" in your code is not just a single U+2660, it also has a unicode variation selector U+FE0F: playground
On my machine at least, this makes a visible difference in appearance (which github tries to eliminate by adding a U+FE0F unless I "escape" with a code block):
changed the title [-]Character literal containing only one codepoint rejected (but only if unescaped)[/-][+]Improve diagnostics for character literals containing multiple codepoints[/+]on Sep 7, 2021
A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
Activity
SNCPlay42 commentedon Sep 6, 2021
The spade "character" in your code is not just a single U+2660, it also has a unicode variation selector U+FE0F: playground
On my machine at least, this makes a visible difference in appearance (which github tries to eliminate by adding a U+FE0F unless I "escape" with a code block):
eggyal commentedon Sep 6, 2021
D'oh! Good spot, thanks @SNCPlay42. Perhaps some improved diagnostics could have helped here?
SNCPlay42 commentedon Sep 6, 2021
We have similar diagnostics in other cases of misleading Unicode so that seems like a good idea.
[-]Character literal containing only one codepoint rejected (but only if unescaped)[/-][+]Improve diagnostics for character literals containing multiple codepoints[/+]Rollup merge of rust-lang#88795 - FabianWolff:issue-88684, r=wesleywiser