diff --git a/clippy_lints/src/formatting.rs b/clippy_lints/src/formatting.rs index 7f5715ef691..d06183cb52f 100644 --- a/clippy_lints/src/formatting.rs +++ b/clippy_lints/src/formatting.rs @@ -173,12 +173,19 @@ fn check_else_if(cx: &EarlyContext<'_>, expr: &ast::Expr) { } } +fn has_unary_equivalent(bin_op: ast::BinOpKind) -> bool { + // &, *, - + bin_op == ast::BinOpKind::And + || bin_op == ast::BinOpKind::Mul + || bin_op == ast::BinOpKind::Sub +} + /// Implementation of the `POSSIBLE_MISSING_COMMA` lint for array fn check_array(cx: &EarlyContext<'_>, expr: &ast::Expr) { if let ast::ExprKind::Array(ref array) = expr.node { for element in array { if let ast::ExprKind::Binary(ref op, ref lhs, _) = element.node { - if !differing_macro_contexts(lhs.span, op.span) { + if has_unary_equivalent(op.node) && !differing_macro_contexts(lhs.span, op.span) { let space_span = lhs.span.between(op.span); if let Some(space_snippet) = snippet_opt(cx, space_span) { let lint_span = lhs.span.with_lo(lhs.span.hi()); diff --git a/tests/ui/formatting.rs b/tests/ui/formatting.rs index 0dca8c8585b..88f6e497d12 100644 --- a/tests/ui/formatting.rs +++ b/tests/ui/formatting.rs @@ -112,4 +112,16 @@ fn main() { 1 + 2, 3 + 4, 5 + 6, ]; + + // don't lint for bin op without unary equiv + // issue 3244 + vec![ + 1 + / 2, + ]; + // issue 3396 + vec![ + true + | false, + ]; }