1
Fork 0

Use span_suggestion_with_applicability for "and/or" hinter

Advised by @estebank.
This commit is contained in:
Vitaly _Vi Shukela 2018-09-13 20:40:39 +03:00
parent 888b8c9451
commit acc44e40cc
No known key found for this signature in database
GPG key ID: C097221D6E03DF68
2 changed files with 34 additions and 17 deletions

View file

@ -733,10 +733,20 @@ impl<'a> Parser<'a> {
};
let mut err = self.fatal(&msg_exp);
if self.token.is_ident_named("and") {
err.help("Use `&&` instead of `and` for the boolean operator");
err.span_suggestion_with_applicability(
self.span,
"use `&&` instead of `and` for the boolean operator",
"&&".to_string(),
Applicability::MaybeIncorrect,
);
}
if self.token.is_ident_named("or") {
err.help("Use `||` instead of `or` for the boolean operator");
err.span_suggestion_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
@ -4758,10 +4768,20 @@ impl<'a> Parser<'a> {
}
if self.token.is_ident_named("and") {
e.help("Use `&&` instead of `and` for the boolean operator");
e.span_suggestion_with_applicability(
self.span,
"use `&&` instead of `and` for the boolean operator",
"&&".to_string(),
Applicability::MaybeIncorrect,
);
}
if self.token.is_ident_named("or") {
e.help("Use `||` instead of `or` for the boolean operator");
e.span_suggestion_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