Skip to content

Commit 8ae01a9

Browse files
committed
Use Symbol equality in is_ident_named.
1 parent 303bf15 commit 8ae01a9

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/libsyntax/parse/diagnostics.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, Token
88
use crate::print::pprust;
99
use crate::ptr::P;
1010
use crate::source_map::Spanned;
11-
use crate::symbol::kw;
11+
use crate::symbol::{kw, sym};
1212
use crate::ThinVec;
1313
use crate::util::parser::AssocOp;
1414
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
@@ -263,15 +263,15 @@ impl<'a> Parser<'a> {
263263
};
264264
self.last_unexpected_token_span = Some(self.span);
265265
let mut err = self.fatal(&msg_exp);
266-
if self.token.is_ident_named("and") {
266+
if self.token.is_ident_named(sym::and) {
267267
err.span_suggestion_short(
268268
self.span,
269269
"use `&&` instead of `and` for the boolean operator",
270270
"&&".to_string(),
271271
Applicability::MaybeIncorrect,
272272
);
273273
}
274-
if self.token.is_ident_named("or") {
274+
if self.token.is_ident_named(sym::or) {
275275
err.span_suggestion_short(
276276
self.span,
277277
"use `||` instead of `or` for the boolean operator",

src/libsyntax/parse/parser.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -2759,7 +2759,7 @@ impl<'a> Parser<'a> {
27592759
let (span, e) = self.interpolated_or_expr_span(e)?;
27602760
(lo.to(span), ExprKind::Box(e))
27612761
}
2762-
token::Ident(..) if self.token.is_ident_named("not") => {
2762+
token::Ident(..) if self.token.is_ident_named(sym::not) => {
27632763
// `not` is just an ordinary identifier in Rust-the-language,
27642764
// but as `rustc`-the-compiler, we can issue clever diagnostics
27652765
// for confused users who really want to say `!`
@@ -4592,15 +4592,15 @@ impl<'a> Parser<'a> {
45924592
let do_not_suggest_help =
45934593
self.token.is_keyword(kw::In) || self.token == token::Colon;
45944594

4595-
if self.token.is_ident_named("and") {
4595+
if self.token.is_ident_named(sym::and) {
45964596
e.span_suggestion_short(
45974597
self.span,
45984598
"use `&&` instead of `and` for the boolean operator",
45994599
"&&".to_string(),
46004600
Applicability::MaybeIncorrect,
46014601
);
46024602
}
4603-
if self.token.is_ident_named("or") {
4603+
if self.token.is_ident_named(sym::or) {
46044604
e.span_suggestion_short(
46054605
self.span,
46064606
"use `||` instead of `or` for the boolean operator",

src/libsyntax/parse/token.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,9 @@ impl Token {
391391

392392
/// Returns `true` if the token is a identifier whose name is the given
393393
/// string slice.
394-
crate fn is_ident_named(&self, name: &str) -> bool {
394+
crate fn is_ident_named(&self, name: Symbol) -> bool {
395395
match self.ident() {
396-
Some((ident, _)) => ident.as_str() == name,
396+
Some((ident, _)) => ident.name == name,
397397
None => false
398398
}
399399
}

src/libsyntax_pos/symbol.rs

+2
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ symbols! {
133133
allow_internal_unstable,
134134
allow_internal_unstable_backcompat_hack,
135135
always,
136+
and,
136137
any,
137138
arbitrary_self_types,
138139
Arguments,
@@ -420,6 +421,7 @@ symbols! {
420421
option,
421422
Option,
422423
opt_out_copy,
424+
or,
423425
Ord,
424426
Ordering,
425427
Output,

0 commit comments

Comments
 (0)