Skip to content

Commit 636f518

Browse files
committed
Suggest && and || instead of 'and' and 'or'
Closes #54109.
1 parent 06d2448 commit 636f518

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -732,6 +732,12 @@ impl<'a> Parser<'a> {
732732
format!("expected {} here", expect)))
733733
};
734734
let mut err = self.fatal(&msg_exp);
735+
if self.token.is_ident_named("and") {
736+
err.help("Use `&&` instead of `and` for the boolean operator");
737+
}
738+
if self.token.is_ident_named("or") {
739+
err.help("Use `||` instead of `or` for the boolean operator");
740+
}
735741
let sp = if self.token == token::Token::Eof {
736742
// This is EOF, don't want to point at the following char, but rather the last token
737743
self.prev_span
@@ -4751,6 +4757,13 @@ impl<'a> Parser<'a> {
47514757
e.span_label(sp, "expected `{`");
47524758
}
47534759

4760+
if self.token.is_ident_named("and") {
4761+
e.help("Use `&&` instead of `and` for the boolean operator");
4762+
}
4763+
if self.token.is_ident_named("or") {
4764+
e.help("Use `||` instead of `or` for the boolean operator");
4765+
}
4766+
47544767
// Check to see if the user has written something like
47554768
//
47564769
// if (cond)

0 commit comments

Comments
 (0)