Uh oh!
There was an error while loading. Please reload this page.
Improve error message for char literals - #28887
Conversation
rust-highfive
commented
Oct 7, 2015
r? @sfackler (rust_highfive has picked a reviewer for you, use r? to override) |
alexcrichton
commented
Oct 7, 2015
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 |
steveklabnik
commented
Oct 7, 2015
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? |
nagisa
commented
Oct 7, 2015
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. |
steveklabnik
commented
Oct 7, 2015
I think some notes would be really good, actually. |
steveklabnik
commented
Oct 23, 2015
I've updated this with a better message. What do you think? |
bors
commented
Nov 3, 2015
☔ The latest upstream changes (presumably #29285) made this pull request unmergeable. Please resolve the merge conflicts. |
steveklabnik
commented
Nov 3, 2015
Rebased. |
alexcrichton
commented
Nov 3, 2015
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.
Fixesrust-lang#28851steveklabnik
commented
Nov 5, 2015
@bors: r=alexcrichton |
bors
commented
Nov 5, 2015
📌 Commit 00e9ad1 has been approved by |
bors
commented
Nov 5, 2015
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