about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-09-16 12:25:42 +0200
committerGitHub <noreply@github.com>2018-09-16 12:25:42 +0200
commit54a1d2b1314530c71831b777aabba8b117f14c5b (patch)
treeeb58bab487584f9fd2aa5fc1372590f657129440 /src/libsyntax
parent3466d8044fdd9a72dc07c79fd74659f95acc5c1e (diff)
parentbc63a4a13a442e1844bb5577adcc464c2a6bfd21 (diff)
downloadrust-54a1d2b1314530c71831b777aabba8b117f14c5b.tar.gz
rust-54a1d2b1314530c71831b777aabba8b117f14c5b.zip
Rollup merge of #54181 - vi:hint_and_or, r=estebank
Suggest && and || instead of 'and' and 'or'

Resolves #54109.

Note: competing pull reqeust: #54179

r? @csmoe
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/parse/parser.rs33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs
index f57fca2cfcf..48e034b117f 100644
--- a/src/libsyntax/parse/parser.rs
+++ b/src/libsyntax/parse/parser.rs
@@ -732,6 +732,22 @@ impl<'a> Parser<'a> {
                   format!("expected {} here", expect)))
             };
             let mut err = self.fatal(&msg_exp);
+            if self.token.is_ident_named("and") {
+                err.span_suggestion_short_with_applicability(
+                    self.span,
+                    "use `&&` instead of `and` for the boolean operator",
+                    "&&".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
+            }
+            if self.token.is_ident_named("or") {
+                err.span_suggestion_short_with_applicability(
+                    self.span,
+                    "use `||` instead of `or` for the boolean operator",
+                    "||".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
+            }
             let sp = if self.token == token::Token::Eof {
                 // This is EOF, don't want to point at the following char, but rather the last token
                 self.prev_span
@@ -4751,6 +4767,23 @@ impl<'a> Parser<'a> {
                 e.span_label(sp, "expected `{`");
             }
 
+            if self.token.is_ident_named("and") {
+                e.span_suggestion_short_with_applicability(
+                    self.span,
+                    "use `&&` instead of `and` for the boolean operator",
+                    "&&".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
+            }
+            if self.token.is_ident_named("or") {
+                e.span_suggestion_short_with_applicability(
+                    self.span,
+                    "use `||` instead of `or` for the boolean operator",
+                    "||".to_string(),
+                    Applicability::MaybeIncorrect,
+                );
+            }
+
             // Check to see if the user has written something like
             //
             //    if (cond)