Skip to content

Commit 0ca3c2f

Browse files
committed
syntax: Move most of the TokenKind methods to Token
1 parent ffe2347 commit 0ca3c2f

File tree

9 files changed

+66
-100
lines changed

9 files changed

+66
-100
lines changed

src/librustdoc/html/highlight.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,7 +257,7 @@ impl<'a> Classifier<'a> {
257257
token::Question => Class::QuestionMark,
258258

259259
token::Dollar => {
260-
if self.lexer.peek().kind.is_ident() {
260+
if self.lexer.peek().is_ident() {
261261
self.in_macro_nonterminal = true;
262262
Class::MacroNonTerminal
263263
} else {

src/libsyntax/attr/mod.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::source_map::{BytePos, Spanned, dummy_spanned};
2020
use crate::parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
2121
use crate::parse::parser::Parser;
2222
use crate::parse::{self, ParseSess, PResult};
23-
use crate::parse::token::{self, Token, TokenKind};
23+
use crate::parse::token::{self, Token};
2424
use crate::ptr::P;
2525
use crate::symbol::{sym, Symbol};
2626
use crate::ThinVec;
@@ -467,8 +467,7 @@ impl MetaItem {
467467
segment.ident.span.ctxt());
468468
idents.push(TokenTree::token(token::ModSep, mod_sep_span).into());
469469
}
470-
idents.push(TokenTree::token(TokenKind::from_ast_ident(segment.ident),
471-
segment.ident.span).into());
470+
idents.push(TokenTree::Token(Token::from_ast_ident(segment.ident)).into());
472471
last_pos = segment.ident.span.hi();
473472
}
474473
self.node.tokens(self.span).append_to_tree_and_joint_vec(&mut idents);

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -428,13 +428,13 @@ pub fn parse_failure_msg(tok: TokenKind) -> String {
428428
}
429429

430430
/// Performs a token equality check, ignoring syntax context (that is, an unhygienic comparison)
431-
fn token_name_eq(t1: &TokenKind, t2: &TokenKind) -> bool {
432-
if let (Some((name1, is_raw1)), Some((name2, is_raw2))) = (t1.ident_name(), t2.ident_name()) {
433-
name1 == name2 && is_raw1 == is_raw2
434-
} else if let (Some(name1), Some(name2)) = (t1.lifetime_name(), t2.lifetime_name()) {
435-
name1 == name2
431+
fn token_name_eq(t1: &Token, t2: &Token) -> bool {
432+
if let (Some((ident1, is_raw1)), Some((ident2, is_raw2))) = (t1.ident(), t2.ident()) {
433+
ident1.name == ident2.name && is_raw1 == is_raw2
434+
} else if let (Some(ident1), Some(ident2)) = (t1.lifetime(), t2.lifetime()) {
435+
ident1.name == ident2.name
436436
} else {
437-
*t1 == *t2
437+
t1.kind == t2.kind
438438
}
439439
}
440440

@@ -712,7 +712,7 @@ pub fn parse(
712712

713713
// If we reached the EOF, check that there is EXACTLY ONE possible matcher. Otherwise,
714714
// either the parse is ambiguous (which should never happen) or there is a syntax error.
715-
if token_name_eq(&parser.token, &token::Eof) {
715+
if parser.token == token::Eof {
716716
if eof_items.len() == 1 {
717717
let matches = eof_items[0]
718718
.matches

src/libsyntax/ext/tt/transcribe.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::ext::expand::Marker;
44
use crate::ext::tt::macro_parser::{MatchedNonterminal, MatchedSeq, NamedMatch};
55
use crate::ext::tt::quoted;
66
use crate::mut_visit::noop_visit_tt;
7-
use crate::parse::token::{self, NtTT, Token, TokenKind};
7+
use crate::parse::token::{self, NtTT, Token};
88
use crate::tokenstream::{DelimSpan, TokenStream, TokenTree, TreeAndJoint};
99

1010
use smallvec::{smallvec, SmallVec};
@@ -237,7 +237,7 @@ pub fn transcribe(
237237
Ident::new(ident.name, ident.span.apply_mark(cx.current_expansion.mark));
238238
sp = sp.apply_mark(cx.current_expansion.mark);
239239
result.push(TokenTree::token(token::Dollar, sp).into());
240-
result.push(TokenTree::token(TokenKind::from_ast_ident(ident), sp).into());
240+
result.push(TokenTree::Token(Token::from_ast_ident(ident)).into());
241241
}
242242
}
243243

src/libsyntax/parse/lexer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,7 +1501,7 @@ fn char_at(s: &str, byte: usize) -> char {
15011501
mod tests {
15021502
use super::*;
15031503

1504-
use crate::ast::{Ident, CrateConfig};
1504+
use crate::ast::CrateConfig;
15051505
use crate::symbol::Symbol;
15061506
use crate::source_map::{SourceMap, FilePathMapping};
15071507
use crate::feature_gate::UnstableFeatures;
@@ -1562,7 +1562,7 @@ mod tests {
15621562
assert_eq!(string_reader.next_token(), token::Whitespace);
15631563
let tok1 = string_reader.next_token();
15641564
let tok2 = Token::new(
1565-
token::Ident(Symbol::intern("fn"), false),
1565+
mk_ident("fn"),
15661566
Span::new(BytePos(21), BytePos(23), NO_EXPANSION),
15671567
);
15681568
assert_eq!(tok1.kind, tok2.kind);
@@ -1593,7 +1593,7 @@ mod tests {
15931593

15941594
// make the identifier by looking up the string in the interner
15951595
fn mk_ident(id: &str) -> TokenKind {
1596-
TokenKind::from_ast_ident(Ident::from_str(id))
1596+
token::Ident(Symbol::intern(id), false)
15971597
}
15981598

15991599
fn mk_lit(kind: token::LitKind, symbol: &str, suffix: Option<&str>) -> TokenKind {

src/libsyntax/parse/parser.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2627,9 +2627,11 @@ impl<'a> Parser<'a> {
26272627
token::Ident(name, _) => name,
26282628
_ => unreachable!()
26292629
};
2630-
let mut err = self.fatal(&format!("unknown macro variable `{}`", name));
2631-
err.span_label(self.token.span, "unknown macro variable");
2632-
err.emit();
2630+
let span = self.prev_span.to(self.token.span);
2631+
self.diagnostic()
2632+
.struct_span_fatal(span, &format!("unknown macro variable `{}`", name))
2633+
.span_label(span, "unknown macro variable")
2634+
.emit();
26332635
self.bump();
26342636
return
26352637
}

0 commit comments

Comments
 (0)