De Morgan's Law assist now correctly parenthesizes binary expressions.

This commit is contained in:
lbrande
2021-02-19 14:48:07 +01:00
committed by Lukas Wirth
parent aa38fa1c72
commit f7a4a87de2
3 changed files with 7 additions and 11 deletions

View File

@@ -217,11 +217,8 @@ fn invert_special_case(expr: &ast::Expr) -> Option<ast::Expr> {
ast::Expr::BinExpr(bin) => match bin.op_kind()? {
ast::BinOp::NegatedEqualityTest => bin.replace_op(T![==]).map(|it| it.into()),
ast::BinOp::EqualityTest => bin.replace_op(T![!=]).map(|it| it.into()),
// Parenthesize composite boolean expressions before prefixing `!`
ast::BinOp::BooleanAnd | ast::BinOp::BooleanOr => {
Some(make::expr_prefix(T![!], make::expr_paren(expr.clone())))
}
_ => None,
// Parenthesize other expressions before prefixing `!`
_ => Some(make::expr_prefix(T![!], make::expr_paren(expr.clone()))),
},
ast::Expr::MethodCallExpr(mce) => {
let receiver = mce.receiver()?;