-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Improve error message for char literals #28887
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
This may want to also consider something like
Printing instead "character literal that's larger than a char" may also be a little misleading perhaps as |
Ahhh yes. I tried to think of a few different things, but you're right that this message has that weakness. I like "multiple code points found", if I change it to that, is this okay? |
I’d change the error message to “char(acter) may only contain/represent 1 codepoint”. Both the previous and suggested error are pretty nasty in case of combining characters like 'ō' or 'ぱ'. The current makes no sense in any case, and the new doesn’t really point out the reason… “'ō'/'ぱ' cannot fit into char even if they’re 1 codepoint? Oh well; I guess I’ll use a string.” If we want to get fancy, we could even add a note pointing existence of combining codepoints in characters. |
I think some notes would be really good, actually. |
I've updated this with a better message. What do you think? |
☔ The latest upstream changes (presumably #29285) made this pull request unmergeable. Please resolve the merge conflicts. |
Rebased. |
@@ -1 +1 @@ | |||
Subproject commit cde1ed3196ba9b39bcf028e06e08a8722113a5cb | |||
Subproject commit 62ad301a2407a7aca50c1d5120c63597d676d29f |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
accidental update?
r=me |
If you try to put something that's bigger than a char into a char literal, you get an error: fn main() { let c = 'ஶ்ரீ'; } error: unterminated character constant: This is a very compiler-centric message. Yes, it's technically 'unterminated', but that's not what you, the user did wrong. Instead, this commit changes it to error: character literal may only contain one codepoint As this actually tells you what went wrong. Fixes rust-lang#28851
@bors: r=alexcrichton |
📌 Commit 00e9ad1 has been approved by |
If you try to put something that's bigger than a char into a char literal, you get an error: fn main() { let c = 'ஶ்ரீ'; } error: unterminated character constant: This is a very compiler-centric message. Yes, it's technically 'unterminated', but that's not what you, the user did wrong. Instead, this commit changes it to error: character literal that's larger than a char: As this actually tells you what went wrong. Fixes #28851
If you try to put something that's bigger than a char into a char
literal, you get an error:
This is a very compiler-centric message. Yes, it's technically
'unterminated', but that's not what you, the user did wrong.
Instead, this commit changes it to
As this actually tells you what went wrong.
Fixes #28851