Skip to content

Commit 5c3d632

Browse files
committed
Return a is_raw parameter from Token::ident rather than having separate methods.
1 parent d2e7953 commit 5c3d632

File tree

3 files changed

+19
-34
lines changed

3 files changed

+19
-34
lines changed

src/libsyntax/ext/tt/macro_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ pub fn parse_failure_msg(tok: Token) -> String {
364364

365365
/// Perform a token equality check, ignoring syntax context (that is, an unhygienic comparison)
366366
fn token_name_eq(t1: &Token, t2: &Token) -> bool {
367-
if let (Some(id1), Some(id2)) = (t1.ident(), t2.ident()) {
368-
id1.name == id2.name && t1.is_raw_ident() == t2.is_raw_ident()
367+
if let (Some((id1, is_raw1)), Some((id2, is_raw2))) = (t1.ident(), t2.ident()) {
368+
id1.name == id2.name && is_raw1 == is_raw2
369369
} else if let (&token::Lifetime(id1), &token::Lifetime(id2)) = (t1, t2) {
370370
id1.name == id2.name
371371
} else {

src/libsyntax/ext/tt/quoted.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ pub fn parse(
200200
let span = match trees.next() {
201201
Some(tokenstream::TokenTree::Token(span, token::Colon)) => match trees.next() {
202202
Some(tokenstream::TokenTree::Token(end_sp, ref tok)) => match tok.ident() {
203-
Some(kind) => {
203+
Some((kind, _)) => {
204204
let span = end_sp.with_lo(start_sp.lo());
205205
result.push(TokenTree::MetaVarDecl(span, ident, kind));
206206
continue;
@@ -289,7 +289,7 @@ where
289289
// `tree` is followed by an `ident`. This could be `$meta_var` or the `$crate` special
290290
// metavariable that names the crate of the invokation.
291291
Some(tokenstream::TokenTree::Token(ident_span, ref token)) if token.is_ident() => {
292-
let ident = token.ident().unwrap();
292+
let (ident, _) = token.ident().unwrap();
293293
let span = ident_span.with_lo(span.lo());
294294
if ident.name == keywords::Crate.name() {
295295
let ident = ast::Ident {

src/libsyntax/parse/token.rs

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -310,32 +310,17 @@ impl Token {
310310
}
311311
}
312312

313-
fn ident_common(&self, allow_raw: bool) -> Option<ast::Ident> {
313+
pub fn ident(&self) -> Option<(ast::Ident, bool)> {
314314
match *self {
315-
Ident(ident, is_raw) if !is_raw || allow_raw => Some(ident),
315+
Ident(ident, is_raw) => Some((ident, is_raw)),
316316
Interpolated(ref nt) => match nt.0 {
317-
NtIdent(ident, is_raw) if !is_raw || allow_raw => Some(ident.node),
317+
NtIdent(ident, is_raw) => Some((ident.node, is_raw)),
318318
_ => None,
319319
},
320320
_ => None,
321321
}
322322
}
323323

324-
pub fn nonraw_ident(&self) -> Option<ast::Ident> {
325-
self.ident_common(false)
326-
}
327-
328-
pub fn is_raw_ident(&self) -> bool {
329-
match *self {
330-
Ident(_, true) => true,
331-
_ => false,
332-
}
333-
}
334-
335-
pub fn ident(&self) -> Option<ast::Ident> {
336-
self.ident_common(true)
337-
}
338-
339324
/// Returns `true` if the token is an identifier.
340325
pub fn is_ident(&self) -> bool {
341326
self.ident().is_some()
@@ -404,37 +389,37 @@ impl Token {
404389

405390
/// Returns `true` if the token is a given keyword, `kw`.
406391
pub fn is_keyword(&self, kw: keywords::Keyword) -> bool {
407-
self.nonraw_ident().map(|ident| ident.name == kw.name()).unwrap_or(false)
392+
self.ident().map(|(ident, is_raw)| ident.name == kw.name() && !is_raw).unwrap_or(false)
408393
}
409394

410395
pub fn is_path_segment_keyword(&self) -> bool {
411-
match self.nonraw_ident() {
412-
Some(id) => is_path_segment_keyword(id),
413-
None => false,
396+
match self.ident() {
397+
Some((id, false)) => is_path_segment_keyword(id),
398+
_ => false,
414399
}
415400
}
416401

417402
// Returns true for reserved identifiers used internally for elided lifetimes,
418403
// unnamed method parameters, crate root module, error recovery etc.
419404
pub fn is_special_ident(&self) -> bool {
420-
match self.nonraw_ident() {
421-
Some(id) => is_special_ident(id),
405+
match self.ident() {
406+
Some((id, false)) => is_special_ident(id),
422407
_ => false,
423408
}
424409
}
425410

426411
/// Returns `true` if the token is a keyword used in the language.
427412
pub fn is_used_keyword(&self) -> bool {
428-
match self.nonraw_ident() {
429-
Some(id) => is_used_keyword(id),
413+
match self.ident() {
414+
Some((id, false)) => is_used_keyword(id),
430415
_ => false,
431416
}
432417
}
433418

434419
/// Returns `true` if the token is a keyword reserved for possible future use.
435420
pub fn is_unused_keyword(&self) -> bool {
436-
match self.nonraw_ident() {
437-
Some(id) => is_unused_keyword(id),
421+
match self.ident() {
422+
Some((id, false)) => is_unused_keyword(id),
438423
_ => false,
439424
}
440425
}
@@ -507,8 +492,8 @@ impl Token {
507492

508493
/// Returns `true` if the token is either a special identifier or a keyword.
509494
pub fn is_reserved_ident(&self) -> bool {
510-
match self.nonraw_ident() {
511-
Some(id) => is_reserved_ident(id),
495+
match self.ident() {
496+
Some((id, false)) => is_reserved_ident(id),
512497
_ => false,
513498
}
514499
}

0 commit comments

Comments
 (0)