]> git.lizzy.rs Git - rust.git/commitdiff
Suggest && and || instead of 'and' and 'or'
authorVitaly _Vi Shukela <vi0oss@gmail.com>
Thu, 13 Sep 2018 12:54:12 +0000 (15:54 +0300)
committerVitaly _Vi Shukela <vi0oss@gmail.com>
Thu, 13 Sep 2018 12:54:12 +0000 (15:54 +0300)
Closes #54109.

src/libsyntax/parse/parser.rs

index f57fca2cfcf604683b7c6489f72939548a220616..a28157106ba7d1951572630e1df1270899257072 100644 (file)
@@ -732,6 +732,12 @@ fn tokens_to_string(tokens: &[TokenType]) -> String {
                   format!("expected {} here", expect)))
             };
             let mut err = self.fatal(&msg_exp);
+            if self.token.is_ident_named("and") {
+                err.help("Use `&&` instead of `and` for the boolean operator");
+            }
+            if self.token.is_ident_named("or") {
+                err.help("Use `||` instead of `or` for the boolean operator");
+            }
             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 +4757,13 @@ pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
                 e.span_label(sp, "expected `{`");
             }
 
+            if self.token.is_ident_named("and") {
+                e.help("Use `&&` instead of `and` for the boolean operator");
+            }
+            if self.token.is_ident_named("or") {
+                e.help("Use `||` instead of `or` for the boolean operator");
+            }
+
             // Check to see if the user has written something like
             //
             //    if (cond)