@@ -18,57 +18,65 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, op: BinOpKind, lhs: &
1818 if op == BinOpKind :: Div
1919 && check_int_ty_and_feature ( cx, lhs)
2020 && check_int_ty_and_feature ( cx, rhs)
21- && let ExprKind :: Binary ( inner_op, inner_lhs, inner_rhs) = lhs. kind
2221 && msrv. meets ( cx, msrvs:: DIV_CEIL )
2322 {
24- // (x + (y - 1)) / y
25- if let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = inner_rhs. kind
26- && inner_op. node == BinOpKind :: Add
27- && sub_op. node == BinOpKind :: Sub
28- && check_literal ( sub_rhs)
29- && check_eq_expr ( cx, sub_lhs, rhs)
30- {
31- build_suggestion ( cx, expr, inner_lhs, rhs, & mut applicability) ;
32- return ;
33- }
23+ if let ExprKind :: Binary ( inner_op, inner_lhs, inner_rhs) = lhs. kind {
24+ // (x + (y - 1)) / y
25+ if let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = inner_rhs. kind
26+ && inner_op. node == BinOpKind :: Add
27+ && sub_op. node == BinOpKind :: Sub
28+ && check_literal ( sub_rhs)
29+ && check_eq_expr ( cx, sub_lhs, rhs)
30+ {
31+ build_suggestion ( cx, expr, inner_lhs, rhs, & mut applicability) ;
32+ return ;
33+ }
3434
35- // ((y - 1) + x) / y
36- if let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = inner_lhs. kind
37- && inner_op. node == BinOpKind :: Add
38- && sub_op. node == BinOpKind :: Sub
39- && check_literal ( sub_rhs)
40- && check_eq_expr ( cx, sub_lhs, rhs)
41- {
42- build_suggestion ( cx, expr, inner_rhs, rhs, & mut applicability) ;
43- return ;
44- }
35+ // ((y - 1) + x) / y
36+ if let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = inner_lhs. kind
37+ && inner_op. node == BinOpKind :: Add
38+ && sub_op. node == BinOpKind :: Sub
39+ && check_literal ( sub_rhs)
40+ && check_eq_expr ( cx, sub_lhs, rhs)
41+ {
42+ build_suggestion ( cx, expr, inner_rhs, rhs, & mut applicability) ;
43+ return ;
44+ }
4545
46- // (x + y - 1) / y
47- if let ExprKind :: Binary ( add_op, add_lhs, add_rhs) = inner_lhs. kind
48- && inner_op. node == BinOpKind :: Sub
49- && add_op. node == BinOpKind :: Add
50- && check_literal ( inner_rhs)
51- && check_eq_expr ( cx, add_rhs, rhs)
52- {
53- build_suggestion ( cx, expr, add_lhs, rhs, & mut applicability) ;
54- }
46+ // (x + y - 1) / y
47+ if let ExprKind :: Binary ( add_op, add_lhs, add_rhs) = inner_lhs. kind
48+ && inner_op. node == BinOpKind :: Sub
49+ && add_op. node == BinOpKind :: Add
50+ && check_literal ( inner_rhs)
51+ && check_eq_expr ( cx, add_rhs, rhs)
52+ {
53+ build_suggestion ( cx, expr, add_lhs, rhs, & mut applicability) ;
54+ }
5555
56- // (x + (Y - 1)) / Y
57- if inner_op. node == BinOpKind :: Add && differ_by_one ( inner_rhs, rhs) {
58- build_suggestion ( cx, expr, inner_lhs, rhs, & mut applicability) ;
59- }
56+ // (x + (Y - 1)) / Y
57+ if inner_op. node == BinOpKind :: Add && differ_by_one ( inner_rhs, rhs) {
58+ build_suggestion ( cx, expr, inner_lhs, rhs, & mut applicability) ;
59+ }
6060
61- // ((Y - 1) + x) / Y
62- if inner_op. node == BinOpKind :: Add && differ_by_one ( inner_lhs, rhs) {
63- build_suggestion ( cx, expr, inner_rhs, rhs, & mut applicability) ;
64- }
61+ // ((Y - 1) + x) / Y
62+ if inner_op. node == BinOpKind :: Add && differ_by_one ( inner_lhs, rhs) {
63+ build_suggestion ( cx, expr, inner_rhs, rhs, & mut applicability) ;
64+ }
6565
66- // (x - (-Y - 1)) / Y
67- if inner_op. node == BinOpKind :: Sub
68- && let ExprKind :: Unary ( UnOp :: Neg , abs_div_rhs) = rhs. kind
69- && differ_by_one ( abs_div_rhs, inner_rhs)
66+ // (x - (-Y - 1)) / Y
67+ if inner_op. node == BinOpKind :: Sub
68+ && let ExprKind :: Unary ( UnOp :: Neg , abs_div_rhs) = rhs. kind
69+ && differ_by_one ( abs_div_rhs, inner_rhs)
70+ {
71+ build_suggestion ( cx, expr, inner_lhs, rhs, & mut applicability) ;
72+ }
73+ } else if let ExprKind :: MethodCall ( method, receiver, [ next_multiple_of_arg] , _) = lhs. kind
74+ && method. ident . name == sym:: next_multiple_of
75+ && check_int_ty_and_feature ( cx, receiver)
76+ && check_eq_expr ( cx, next_multiple_of_arg, rhs)
7077 {
71- build_suggestion ( cx, expr, inner_lhs, rhs, & mut applicability) ;
78+ // x.next_multiple_of(Y) / Y
79+ build_suggestion ( cx, expr, receiver, rhs, & mut applicability) ;
7280 }
7381 }
7482}
0 commit comments