about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <nnethercote@mozilla.com>2019-05-23 15:31:43 +1000
committerNicholas Nethercote <nnethercote@mozilla.com>2019-05-27 14:05:05 +1000
commit8ae01a90088fd62987030ff382733ed67791d4f8 (patch)
treed6f6c82e6947ad24823f60df40b2d5d89f6c72ac
parent303bf1509bdf5ffd150539acf44f1c500c7079bd (diff)
downloadrust-8ae01a90088fd62987030ff382733ed67791d4f8.tar.gz
rust-8ae01a90088fd62987030ff382733ed67791d4f8.zip
Use `Symbol` equality in `is_ident_named`.
-rw-r--r--src/libsyntax/parse/diagnostics.rs6
-rw-r--r--src/libsyntax/parse/parser.rs6
-rw-r--r--src/libsyntax/parse/token.rs4
-rw-r--r--src/libsyntax_pos/symbol.rs2
4 files changed, 10 insertions, 8 deletions
diff --git a/src/libsyntax/parse/diagnostics.rs b/src/libsyntax/parse/diagnostics.rs
index 9431b559da5..b3d49524d76 100644
--- a/src/libsyntax/parse/diagnostics.rs
+++ b/src/libsyntax/parse/diagnostics.rs
@@ -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",
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index e0430ac5563..07efeaa4cf2 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -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",
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index e5361b2db4e..47185df8d61 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -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
         }
     }
diff --git a/src/libsyntax_pos/symbol.rs b/src/libsyntax_pos/symbol.rs
index 6167a90b22a..da6c41adfd9 100644
--- a/src/libsyntax_pos/symbol.rs
+++ b/src/libsyntax_pos/symbol.rs
@@ -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,