Skip to content

Improve diagnostics for character literals containing multiple codepoints #88684

Closed
@eggyal

Description

@eggyal

I tried to compile the following code (playground):

const SPADE: 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 = "♠️";
  |                     ^^^

Notably, it is accepted if unicode-escaped:

const SPADE: char = '\u{2660}';

Meta

rustc --version --verbose:

rustc 1.57.0-nightly (e30b68353 2021-09-05)
binary: rustc
commit-hash: e30b68353fe22b00f40d021e7914eeb78473b3c1
commit-date: 2021-09-05
host: x86_64-apple-darwin
release: 1.57.0-nightly
LLVM version: 13.0.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    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.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions