Use span_suggestion_with_applicability for "and/or" hinter
Advised by @estebank.
This commit is contained in:
parent
888b8c9451
commit
acc44e40cc
2 changed files with 34 additions and 17 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue