Skip to content

Commit 5326361

Browse files
committed
Remove trivia tokens
1 parent 8f24c2e commit 5326361

File tree

5 files changed

+5
-28
lines changed

5 files changed

+5
-28
lines changed

compiler/rustc_ast/src/token.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -251,17 +251,6 @@ pub enum TokenKind {
251251
/// similarly to symbols in string literal tokens.
252252
DocComment(CommentKind, ast::AttrStyle, Symbol),
253253

254-
// Junk. These carry no data because we don't really care about the data
255-
// they *would* carry, and don't really want to allocate a new ident for
256-
// them. Instead, users could extract that from the associated span.
257-
/// Whitespace.
258-
Whitespace,
259-
/// A comment.
260-
Comment,
261-
Shebang(Symbol),
262-
/// A completely invalid token which should be skipped.
263-
Unknown(Symbol),
264-
265254
Eof,
266255
}
267256

@@ -331,7 +320,7 @@ impl Token {
331320

332321
/// Some token that will be thrown away later.
333322
pub fn dummy() -> Self {
334-
Token::new(TokenKind::Whitespace, DUMMY_SP)
323+
Token::new(TokenKind::Question, DUMMY_SP)
335324
}
336325

337326
/// Recovers a `Token` from an `Ident`. This creates a raw identifier if necessary.
@@ -360,7 +349,7 @@ impl Token {
360349
pub fn is_op(&self) -> bool {
361350
match self.kind {
362351
OpenDelim(..) | CloseDelim(..) | Literal(..) | DocComment(..) | Ident(..)
363-
| Lifetime(..) | Interpolated(..) | Whitespace | Comment | Shebang(..) | Eof => false,
352+
| Lifetime(..) | Interpolated(..) | Eof => false,
364353
_ => true,
365354
}
366355
}
@@ -676,8 +665,7 @@ impl Token {
676665
Le | EqEq | Ne | Ge | AndAnd | OrOr | Tilde | BinOpEq(..) | At | DotDotDot
677666
| DotDotEq | Comma | Semi | ModSep | RArrow | LArrow | FatArrow | Pound | Dollar
678667
| Question | OpenDelim(..) | CloseDelim(..) | Literal(..) | Ident(..)
679-
| Lifetime(..) | Interpolated(..) | DocComment(..) | Whitespace | Comment
680-
| Shebang(..) | Unknown(..) | Eof => return None,
668+
| Lifetime(..) | Interpolated(..) | DocComment(..) | Eof => return None,
681669
};
682670

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

compiler/rustc_ast_pretty/src/pprust.rs

-4
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,6 @@ fn token_kind_to_string_ext(tok: &TokenKind, convert_dollar_crate: Option<Span>)
289289
doc_comment_to_string(comment_kind, attr_style, data)
290290
}
291291
token::Eof => "<eof>".to_string(),
292-
token::Whitespace => " ".to_string(),
293-
token::Comment => "/* */".to_string(),
294-
token::Shebang(s) => format!("/* shebang: {}*/", s),
295-
token::Unknown(s) => s.to_string(),
296292

297293
token::Interpolated(ref nt) => nonterminal_to_string(nt),
298294
}

compiler/rustc_expand/src/proc_macro_server.rs

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

191191
OpenDelim(..) | CloseDelim(..) => unreachable!(),
192-
Whitespace | Comment | Shebang(..) | Unknown(..) | Eof => unreachable!(),
192+
Eof => unreachable!(),
193193
}
194194
}
195195
}

compiler/rustc_parse/src/lexer/unicode_chars.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ const UNICODE_ARRAY: &[(char, &str, char)] = &[
303303
// However, we should first remove compound tokens like `<<` from `rustc_lexer`, and then add
304304
// fancier error recovery to it, as there will be less overall work to do this way.
305305
const ASCII_ARRAY: &[(char, &str, Option<token::TokenKind>)] = &[
306-
(' ', "Space", Some(token::Whitespace)),
306+
(' ', "Space", None),
307307
('_', "Underscore", Some(token::Ident(kw::Underscore, false))),
308308
('-', "Minus/Hyphen", Some(token::BinOp(token::Minus))),
309309
(',', "Comma", Some(token::Comma)),

compiler/rustc_parse/src/lib.rs

-7
Original file line numberDiff line numberDiff line change
@@ -348,9 +348,6 @@ pub fn tokenstream_probably_equal_for_proc_macro(
348348
| token::CloseDelim(DelimToken::NoDelim)
349349
// The pretty printer collapses many semicolons into one.
350350
| token::Semi
351-
// The pretty printer collapses whitespace arbitrarily and can
352-
// introduce whitespace from `NoDelim`.
353-
| token::Whitespace
354351
// The pretty printer can turn `$crate` into `::crate_name`
355352
| token::ModSep = token.kind {
356353
return false;
@@ -506,8 +503,6 @@ fn token_probably_equal_for_proc_macro(first: &Token, other: &Token) -> bool {
506503
| (&Pound, &Pound)
507504
| (&Dollar, &Dollar)
508505
| (&Question, &Question)
509-
| (&Whitespace, &Whitespace)
510-
| (&Comment, &Comment)
511506
| (&Eof, &Eof) => true,
512507

513508
(&BinOp(a), &BinOp(b)) | (&BinOpEq(a), &BinOpEq(b)) => a == b,
@@ -516,8 +511,6 @@ fn token_probably_equal_for_proc_macro(first: &Token, other: &Token) -> bool {
516511

517512
(&DocComment(a1, a2, a3), &DocComment(b1, b2, b3)) => a1 == b1 && a2 == b2 && a3 == b3,
518513

519-
(&Shebang(a), &Shebang(b)) => a == b,
520-
521514
(&Literal(a), &Literal(b)) => a == b,
522515

523516
(&Lifetime(a), &Lifetime(b)) => a == b,

0 commit comments

Comments
 (0)