fix incorrect suggestion in suboptimal_flops
There was an error when trying to negate an expression like `x - 1.0`. We used to format it as `-x - 1.0` whereas a proper negation would be `-(x - 1.0)`. Therefore, we add parentheses around the expression when it is a Binary ExprKind. We also add parentheses around multiply and divide expressions, even though this is not strictly necessary.
This commit is contained in:
parent
e2a687da72
commit
6bb6dd64d4
4 changed files with 62 additions and 2 deletions
|
|
@ -324,7 +324,7 @@ fn check_powi(cx: &LateContext<'_>, expr: &Expr<'_>, receiver: &Expr<'_>, args:
|
|||
let maybe_neg_sugg = |expr, hir_id| {
|
||||
let sugg = Sugg::hir(cx, expr, "..");
|
||||
if matches!(op, BinOpKind::Sub) && hir_id == rhs.hir_id {
|
||||
format!("-{sugg}")
|
||||
format!("-{}", sugg.maybe_par())
|
||||
} else {
|
||||
sugg.to_string()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue