Skip to content

Commit 792a9f1

Browse files
committed
Auto merge of #28887 - steveklabnik:gh28851, r=alexcrichton
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
2 parents 7839827 + 00e9ad1 commit 792a9f1

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/libsyntax/parse/lexer/mod.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -1081,11 +1081,12 @@ impl<'a> StringReader<'a> {
10811081
if !self.curr_is('\'') {
10821082
let last_bpos = self.last_pos;
10831083
panic!(self.fatal_span_verbose(
1084-
// Byte offsetting here is okay because the
1085-
// character before position `start` is an
1086-
// ascii single quote.
1087-
start - BytePos(1), last_bpos,
1088-
"unterminated character constant".to_string()));
1084+
// Byte offsetting here is okay because the
1085+
// character before position `start` is an
1086+
// ascii single quote.
1087+
start - BytePos(1), last_bpos,
1088+
1089+
String::from("character literal may only contain one codepoint")));
10891090
}
10901091
let id = if valid { self.name_from(start) } else { token::intern("0") };
10911092
self.bump(); // advance curr past token

src/test/parse-fail/lex-bad-char-literals.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ static s: &'static str =
2525
"\●" //~ ERROR: unknown character escape
2626
;
2727

28-
// THIS MUST BE LAST, since unterminated character constants kill the lexer
28+
// THIS MUST BE LAST, since it kills the lexer
2929

3030
static c: char =
31-
'//~ ERROR: unterminated character constant
31+
'//~ ERROR: character literal may only contain one codepoint
3232
;

0 commit comments

Comments
 (0)