Improve error message for char literals
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 #28851
This commit is contained in:
@@ -1085,7 +1085,8 @@ impl<'a> StringReader<'a> {
|
|||||||
// character before position `start` is an
|
// character before position `start` is an
|
||||||
// ascii single quote.
|
// ascii single quote.
|
||||||
start - BytePos(1), last_bpos,
|
start - BytePos(1), last_bpos,
|
||||||
"unterminated character constant".to_string()));
|
|
||||||
|
String::from("character literal may only contain one codepoint")));
|
||||||
}
|
}
|
||||||
let id = if valid { self.name_from(start) } else { token::intern("0") };
|
let id = if valid { self.name_from(start) } else { token::intern("0") };
|
||||||
self.bump(); // advance curr past token
|
self.bump(); // advance curr past token
|
||||||
|
|||||||
@@ -25,8 +25,8 @@ static s: &'static str =
|
|||||||
"\●" //~ ERROR: unknown character escape
|
"\●" //~ ERROR: unknown character escape
|
||||||
;
|
;
|
||||||
|
|
||||||
// THIS MUST BE LAST, since unterminated character constants kill the lexer
|
// THIS MUST BE LAST, since it kills the lexer
|
||||||
|
|
||||||
static c: char =
|
static c: char =
|
||||||
'● //~ ERROR: unterminated character constant
|
'● //~ ERROR: character literal may only contain one codepoint
|
||||||
;
|
;
|
||||||
|
|||||||
Reference in New Issue
Block a user