Skip to content

Implement new literal type Err #57651

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Jan 20, 2019
1 change: 1 addition & 0 deletions src/librustc/ich/impls_syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ fn hash_token<'a, 'gcx, W: StableHasherResult>(
match *lit {
token::Lit::Byte(val) |
token::Lit::Char(val) |
token::Lit::Err(val) |
token::Lit::Integer(val) |
token::Lit::Float(val) |
token::Lit::Str_(val) |
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/ext/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ fn expr_mk_token(cx: &ExtCtxt, sp: Span, tok: &token::Token) -> P<ast::Expr> {

token::Literal(token::Byte(i), suf) => return mk_lit!("Byte", suf, i),
token::Literal(token::Char(i), suf) => return mk_lit!("Char", suf, i),
token::Literal(token::Err(i), suf) => return mk_lit!("Err", suf, i),
token::Literal(token::Integer(i), suf) => return mk_lit!("Integer", suf, i),
token::Literal(token::Float(i), suf) => return mk_lit!("Float", suf, i),
token::Literal(token::Str_(i), suf) => return mk_lit!("Str_", suf, i),
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/parse/lexer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1445,7 +1445,7 @@ impl<'a> StringReader<'a> {
format!("\"{}\"", &self.src[start..end]),
Applicability::MachineApplicable
).emit();
return Ok(token::Literal(token::Str_(Symbol::intern("??")), None))
FatalError.raise();
}
if self.ch_is('\n') || self.is_eof() || self.ch_is('/') {
// Only attempt to infer single line string literals. If we encounter
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ crate fn lit_token(lit: token::Lit, suf: Option<Symbol>, diag: Option<(Span, &Ha
match lit {
token::Byte(i) => (true, Some(LitKind::Byte(byte_lit(&i.as_str()).0))),
token::Char(i) => (true, Some(LitKind::Char(char_lit(&i.as_str(), diag).0))),
token::Err(i) => (true, Some(LitKind::Char(char_lit(&i.as_str(), diag).0))),

// There are some valid suffixes for integer and float literals,
// so all the handling is done internally.
Expand Down
2 changes: 2 additions & 0 deletions src/libsyntax/parse/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ impl DelimToken {
pub enum Lit {
Byte(ast::Name),
Char(ast::Name),
Err(ast::Name),
Integer(ast::Name),
Float(ast::Name),
Str_(ast::Name),
Expand All @@ -73,6 +74,7 @@ impl Lit {
match *self {
Byte(_) => "byte literal",
Char(_) => "char literal",
Err(_) => "error literal",
Integer(_) => "integer literal",
Float(_) => "float literal",
Str_(_) | StrRaw(..) => "string literal",
Expand Down
1 change: 1 addition & 0 deletions src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ pub fn token_to_string(tok: &Token) -> String {
let mut out = match lit {
token::Byte(b) => format!("b'{}'", b),
token::Char(c) => format!("'{}'", c),
token::Err(c) => format!("'{}'", c),
token::Float(c) |
token::Integer(c) => c.to_string(),
token::Str_(s) => format!("\"{}\"", s),
Expand Down
1 change: 0 additions & 1 deletion src/test/ui/parser/lex-bad-char-literals-3.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// This test needs to the last one appearing in this file as it kills the parser
static c: char =
'●●' //~ ERROR: character literal may only contain one codepoint
//~| ERROR: mismatched types
;

fn main() {}
12 changes: 1 addition & 11 deletions src/test/ui/parser/lex-bad-char-literals-3.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,5 @@ help: if you meant to write a `str` literal, use double quotes
LL | "●●" //~ ERROR: character literal may only contain one codepoint
| ^^^^

error[E0308]: mismatched types
--> $DIR/lex-bad-char-literals-3.rs:3:5
|
LL | '●●' //~ ERROR: character literal may only contain one codepoint
| ^^^^ expected char, found reference
|
= note: expected type `char`
found type `&'static str`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
1 change: 0 additions & 1 deletion src/test/ui/parser/lex-bad-char-literals-5.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// This test needs to the last one appearing in this file as it kills the parser
static c: char =
'\x10\x10' //~ ERROR: character literal may only contain one codepoint
//~| ERROR: mismatched types
;

fn main() {}
12 changes: 1 addition & 11 deletions src/test/ui/parser/lex-bad-char-literals-5.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,5 @@ help: if you meant to write a `str` literal, use double quotes
LL | "/x10/x10" //~ ERROR: character literal may only contain one codepoint
| ^^^^^^^^^^

error[E0308]: mismatched types
--> $DIR/lex-bad-char-literals-5.rs:4:5
|
LL | '/x10/x10' //~ ERROR: character literal may only contain one codepoint
| ^^^^^^^^^^ expected char, found reference
|
= note: expected type `char`
found type `&'static str`

error: aborting due to 2 previous errors
error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.