From: Vitaly _Vi Shukela Date: Thu, 13 Sep 2018 12:54:12 +0000 (+0300) Subject: Suggest && and || instead of 'and' and 'or' X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=636f518aac7430406dcb410cd7e46b4a217c265c;p=rust.git Suggest && and || instead of 'and' and 'or' Closes #54109. --- diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index f57fca2cfcf..a28157106ba 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -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> { 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)