Skip to content

Commit 58ac81a

Browse files
committed
add unknown token
1 parent b5e35b1 commit 58ac81a

File tree

7 files changed

+10
-6
lines changed

7 files changed

+10
-6
lines changed

src/librustc/ich/impls_syntax.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,8 @@ impl<'a> HashStable<StableHashingContext<'a>> for token::TokenKind {
363363
}
364364

365365
token::DocComment(val) |
366-
token::Shebang(val) => val.hash_stable(hcx, hasher),
366+
token::Shebang(val) |
367+
token::Unknown(val) => val.hash_stable(hcx, hasher),
367368
}
368369
}
369370
}

src/librustdoc/html/highlight.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ impl<'a> Classifier<'a> {
237237
return Ok(());
238238
},
239239

240-
token::Whitespace => Class::None,
240+
token::Whitespace | token::Unknown(..) => Class::None,
241241
token::Comment => Class::Comment,
242242
token::DocComment(..) => Class::DocComment,
243243

src/libsyntax/ext/proc_macro_server.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ impl FromInternal<(TreeAndJoint, &'_ ParseSess, &'_ mut Vec<Self>)>
184184
}
185185

186186
OpenDelim(..) | CloseDelim(..) => unreachable!(),
187-
Whitespace | Comment | Shebang(..) | Eof => unreachable!(),
187+
Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => unreachable!(),
188188
}
189189
}
190190
}

src/libsyntax/parse/lexer/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'a> StringReader<'a> {
354354
// tokens like `<<` from `rustc_lexer`, and then add fancier error recovery to it,
355355
// as there will be less overall work to do this way.
356356
let token = unicode_chars::check_for_substitution(self, start, c, &mut err)
357-
.unwrap_or(token::Whitespace);
357+
.unwrap_or_else(|| token::Unknown(self.symbol_from(start)));
358358
err.emit();
359359
token
360360
}

src/libsyntax/parse/lexer/tokentrees.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl<'a> TokenTreesReader<'a> {
217217
loop {
218218
let token = self.string_reader.next_token();
219219
match token.kind {
220-
token::Whitespace | token::Comment | token::Shebang(_) => {
220+
token::Whitespace | token::Comment | token::Shebang(_) | token::Unknown(_) => {
221221
self.joint_to_prev = NonJoint;
222222
}
223223
_ => {

src/libsyntax/parse/token.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ pub enum TokenKind {
255255
/// A comment.
256256
Comment,
257257
Shebang(ast::Name),
258+
/// A completely invalid token which should be skipped.
259+
Unknown(ast::Name),
258260

259261
Eof,
260262
}
@@ -603,7 +605,7 @@ impl Token {
603605
DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar |
604606
Question | OpenDelim(..) | CloseDelim(..) |
605607
Literal(..) | Ident(..) | Lifetime(..) | Interpolated(..) | DocComment(..) |
606-
Whitespace | Comment | Shebang(..) | Eof => return None,
608+
Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => return None,
607609
};
608610

609611
Some(Token::new(kind, self.span.to(joint.span)))

src/libsyntax/print/pprust.rs

+1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
288288
token::Whitespace => " ".to_string(),
289289
token::Comment => "/* */".to_string(),
290290
token::Shebang(s) => format!("/* shebang: {}*/", s),
291+
token::Unknown(s) => s.to_string(),
291292

292293
token::Interpolated(ref nt) => nonterminal_to_string(nt),
293294
}

0 commit comments

Comments
 (0)