Skip to content

Commit fcb78d6

Browse files
committed
Convert some token functions into methods
1 parent d8b1fa0 commit fcb78d6

File tree

9 files changed

+305
-311
lines changed

9 files changed

+305
-311
lines changed

src/librustc/middle/save/span_utils.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use syntax::codemap::*;
1919
use syntax::parse::lexer;
2020
use syntax::parse::lexer::{Reader,StringReader};
2121
use syntax::parse::token;
22-
use syntax::parse::token::{is_keyword,keywords,is_ident,Token};
22+
use syntax::parse::token::{keywords, Token};
2323

2424
pub struct SpanUtils<'a> {
2525
pub sess: &'a Session,
@@ -97,7 +97,7 @@ impl<'a> SpanUtils<'a> {
9797
return self.make_sub_span(span, result)
9898
}
9999
if bracket_count == 0 &&
100-
(is_ident(&ts.tok) || is_keyword(keywords::Self, &ts.tok)) {
100+
(ts.tok.is_ident() || ts.tok.is_keyword(keywords::Self)) {
101101
result = Some(ts.sp);
102102
}
103103

@@ -120,7 +120,7 @@ impl<'a> SpanUtils<'a> {
120120
return None;
121121
}
122122
if bracket_count == 0 &&
123-
(is_ident(&ts.tok) || is_keyword(keywords::Self, &ts.tok)) {
123+
(ts.tok.is_ident() || ts.tok.is_keyword(keywords::Self)) {
124124
return self.make_sub_span(span, Some(ts.sp));
125125
}
126126

@@ -148,7 +148,7 @@ impl<'a> SpanUtils<'a> {
148148
if (next.tok == token::LParen ||
149149
next.tok == token::Lt) &&
150150
bracket_count == 0 &&
151-
is_ident(&prev.tok) {
151+
prev.tok.is_ident() {
152152
result = Some(prev.sp);
153153
}
154154

@@ -158,7 +158,7 @@ impl<'a> SpanUtils<'a> {
158158
prev = next;
159159
next = toks.next_token();
160160
if next.tok == token::Lt &&
161-
is_ident(&old.tok) {
161+
old.tok.is_ident() {
162162
result = Some(old.sp);
163163
}
164164
}
@@ -170,7 +170,7 @@ impl<'a> SpanUtils<'a> {
170170
_ => 0
171171
};
172172

173-
if is_ident(&prev.tok) && bracket_count == 0 {
173+
if prev.tok.is_ident() && bracket_count == 0 {
174174
last_span = Some(prev.sp);
175175
}
176176
prev = next;
@@ -194,7 +194,7 @@ impl<'a> SpanUtils<'a> {
194194
if (next.tok == token::Lt ||
195195
next.tok == token::Colon) &&
196196
bracket_count == 0 &&
197-
is_ident(&prev.tok) {
197+
prev.tok.is_ident() {
198198
result = Some(prev.sp);
199199
}
200200

@@ -216,7 +216,7 @@ impl<'a> SpanUtils<'a> {
216216
format!("Mis-counted brackets when breaking path? Parsing '{}' in {}, line {}",
217217
self.snippet(span), loc.file.name, loc.line).as_slice());
218218
}
219-
if result.is_none() && is_ident(&prev.tok) && bracket_count == 0 {
219+
if result.is_none() && prev.tok.is_ident() && bracket_count == 0 {
220220
return self.make_sub_span(span, Some(prev.sp));
221221
}
222222
self.make_sub_span(span, result)
@@ -254,7 +254,7 @@ impl<'a> SpanUtils<'a> {
254254
token::BinOp(token::Shr) => -2,
255255
_ => 0
256256
};
257-
if is_ident(&ts.tok) &&
257+
if ts.tok.is_ident() &&
258258
bracket_count == nesting {
259259
result.push(self.make_sub_span(span, Some(ts.sp)).unwrap());
260260
}
@@ -285,7 +285,7 @@ impl<'a> SpanUtils<'a> {
285285
if ts.tok == token::Eof {
286286
return None;
287287
}
288-
if is_keyword(keyword, &ts.tok) {
288+
if ts.tok.is_keyword(keyword) {
289289
let ts = toks.next_token();
290290
if ts.tok == token::Eof {
291291
return None

src/librustdoc/html/highlight.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
101101
token::RParen | token::LBracket | token::LBrace | token::RBrace |
102102
token::Question => "",
103103
token::Dollar => {
104-
if token::is_ident(&lexer.peek().tok) {
104+
if lexer.peek().tok.is_ident() {
105105
is_macro_nonterminal = true;
106106
"macro-nonterminal"
107107
} else {
@@ -146,7 +146,7 @@ fn doit(sess: &parse::ParseSess, mut lexer: lexer::StringReader,
146146
"Option" | "Result" => "prelude-ty",
147147
"Some" | "None" | "Ok" | "Err" => "prelude-val",
148148

149-
_ if token::is_any_keyword(&next.tok) => "kw",
149+
_ if next.tok.is_any_keyword() => "kw",
150150
_ => {
151151
if is_macro_nonterminal {
152152
is_macro_nonterminal = false;

src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ impl PartialEq for Ident {
8282
//
8383
// On the other hand, if the comparison does need to be hygienic,
8484
// one example and its non-hygienic counterpart would be:
85-
// syntax::parse::token::mtwt_token_eq
85+
// syntax::parse::token::Token::mtwt_eq
8686
// syntax::ext::tt::macro_parser::token_name_eq
8787
fail!("not allowed to compare these idents: {}, {}. \
8888
Probably related to issue \\#6993", self, other);

src/libsyntax/ext/format.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ fn parse_args(ecx: &mut ExtCtxt, sp: Span, allow_method: bool,
116116
return (invocation, None);
117117
}
118118
if p.token == token::Eof { break } // accept trailing commas
119-
if named || (token::is_ident(&p.token) &&
120-
p.look_ahead(1, |t| *t == token::Eq)) {
119+
if named || (p.token.is_ident() && p.look_ahead(1, |t| *t == token::Eq)) {
121120
named = true;
122121
let ident = match p.token {
123122
token::Ident(i, _) => {

src/libsyntax/ext/trace_macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,18 @@ use ast;
1212
use codemap::Span;
1313
use ext::base::ExtCtxt;
1414
use ext::base;
15-
use parse::token::{keywords, is_keyword};
15+
use parse::token::keywords;
1616

1717

1818
pub fn expand_trace_macros(cx: &mut ExtCtxt,
1919
sp: Span,
2020
tt: &[ast::TokenTree])
2121
-> Box<base::MacResult+'static> {
2222
match tt {
23-
[ast::TtToken(_, ref tok)] if is_keyword(keywords::True, tok) => {
23+
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::True) => {
2424
cx.set_trace_macros(true);
2525
}
26-
[ast::TtToken(_, ref tok)] if is_keyword(keywords::False, tok) => {
26+
[ast::TtToken(_, ref tok)] if tok.is_keyword(keywords::False) => {
2727
cx.set_trace_macros(false);
2828
}
2929
_ => cx.span_err(sp, "trace_macros! accepts only `true` or `false`"),

src/libsyntax/parse/lexer/comments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ pub fn gather_comments_and_literals(span_diagnostic: &diagnostic::SpanHandler,
367367
rdr.next_token();
368368
//discard, and look ahead; we're working with internal state
369369
let TokenAndSpan { tok, sp } = rdr.peek();
370-
if token::is_lit(&tok) {
370+
if tok.is_lit() {
371371
rdr.with_str_from(bstart, |s| {
372372
debug!("tok lit: {}", s);
373373
literals.push(Literal {lit: s.to_string(), pos: sp.lo});

src/libsyntax/parse/lexer/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,15 +1058,14 @@ impl<'a> StringReader<'a> {
10581058
let keyword_checking_token =
10591059
&token::Ident(keyword_checking_ident, false);
10601060
let last_bpos = self.last_pos;
1061-
if token::is_keyword(token::keywords::Self,
1062-
keyword_checking_token) {
1061+
if keyword_checking_token.is_keyword(token::keywords::Self) {
10631062
self.err_span_(start,
10641063
last_bpos,
10651064
"invalid lifetime name: 'self \
10661065
is no longer a special lifetime");
1067-
} else if token::is_any_keyword(keyword_checking_token) &&
1068-
!token::is_keyword(token::keywords::Static,
1069-
keyword_checking_token) {
1066+
} else if keyword_checking_token.is_any_keyword() &&
1067+
!keyword_checking_token.is_keyword(token::keywords::Static)
1068+
{
10701069
self.err_span_(start,
10711070
last_bpos,
10721071
"invalid lifetime name");

0 commit comments

Comments
 (0)