Use Symbol equality in is_ident_named.

This commit is contained in:
Nicholas Nethercote 2019-05-23 15:31:43 +10:00
parent 303bf1509b
commit 8ae01a9008
4 changed files with 10 additions and 8 deletions

View File

@ -8,7 +8,7 @@ use crate::parse::parser::{BlockMode, PathStyle, SemiColonMode, TokenType, Token
use crate::print::pprust;
use crate::ptr::P;
use crate::source_map::Spanned;
use crate::symbol::kw;
use crate::symbol::{kw, sym};
use crate::ThinVec;
use crate::util::parser::AssocOp;
use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
@ -263,7 +263,7 @@ impl<'a> Parser<'a> {
};
self.last_unexpected_token_span = Some(self.span);
let mut err = self.fatal(&msg_exp);
if self.token.is_ident_named("and") {
if self.token.is_ident_named(sym::and) {
err.span_suggestion_short(
self.span,
"use `&&` instead of `and` for the boolean operator",
@ -271,7 +271,7 @@ impl<'a> Parser<'a> {
Applicability::MaybeIncorrect,
);
}
if self.token.is_ident_named("or") {
if self.token.is_ident_named(sym::or) {
err.span_suggestion_short(
self.span,
"use `||` instead of `or` for the boolean operator",

View File

@ -2759,7 +2759,7 @@ impl<'a> Parser<'a> {
let (span, e) = self.interpolated_or_expr_span(e)?;
(lo.to(span), ExprKind::Box(e))
}
token::Ident(..) if self.token.is_ident_named("not") => {
token::Ident(..) if self.token.is_ident_named(sym::not) => {
// `not` is just an ordinary identifier in Rust-the-language,
// but as `rustc`-the-compiler, we can issue clever diagnostics
// for confused users who really want to say `!`
@ -4592,7 +4592,7 @@ impl<'a> Parser<'a> {
let do_not_suggest_help =
self.token.is_keyword(kw::In) || self.token == token::Colon;
if self.token.is_ident_named("and") {
if self.token.is_ident_named(sym::and) {
e.span_suggestion_short(
self.span,
"use `&&` instead of `and` for the boolean operator",
@ -4600,7 +4600,7 @@ impl<'a> Parser<'a> {
Applicability::MaybeIncorrect,
);
}
if self.token.is_ident_named("or") {
if self.token.is_ident_named(sym::or) {
e.span_suggestion_short(
self.span,
"use `||` instead of `or` for the boolean operator",

View File

@ -391,9 +391,9 @@ impl Token {
/// Returns `true` if the token is a identifier whose name is the given
/// string slice.
crate fn is_ident_named(&self, name: &str) -> bool {
crate fn is_ident_named(&self, name: Symbol) -> bool {
match self.ident() {
Some((ident, _)) => ident.as_str() == name,
Some((ident, _)) => ident.name == name,
None => false
}
}

View File

@ -133,6 +133,7 @@ symbols! {
allow_internal_unstable,
allow_internal_unstable_backcompat_hack,
always,
and,
any,
arbitrary_self_types,
Arguments,
@ -420,6 +421,7 @@ symbols! {
option,
Option,
opt_out_copy,
or,
Ord,
Ordering,
Output,