@@ -61,40 +61,38 @@ impl<'tcx> LateLintPass<'tcx> for ManualDivCeil {
61
61
let mut applicability = Applicability :: MachineApplicable ;
62
62
63
63
if let ExprKind :: Binary ( div_op, div_lhs, div_rhs) = expr. kind
64
+ && div_op. node == BinOpKind :: Div
64
65
&& check_int_ty_and_feature ( cx, div_lhs)
65
66
&& check_int_ty_and_feature ( cx, div_rhs)
66
- && div_op . node == BinOpKind :: Div
67
+ && let ExprKind :: Binary ( inner_op , inner_lhs , inner_rhs ) = div_lhs . kind
67
68
{
68
69
// (x + (y - 1)) / y
69
- if let ExprKind :: Binary ( add_op, add_lhs, add_rhs) = div_lhs. kind
70
- && add_op. node == BinOpKind :: Add
71
- && let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = add_rhs. kind
70
+ if let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = inner_rhs. kind
71
+ && inner_op. node == BinOpKind :: Add
72
72
&& sub_op. node == BinOpKind :: Sub
73
73
&& check_literal ( sub_rhs)
74
74
&& check_eq_expr ( cx, sub_lhs, div_rhs)
75
75
{
76
- build_suggestion ( cx, expr, add_lhs , div_rhs, & mut applicability) ;
76
+ build_suggestion ( cx, expr, inner_lhs , div_rhs, & mut applicability) ;
77
77
return ;
78
78
}
79
79
80
80
// ((y - 1) + x) / y
81
- if let ExprKind :: Binary ( add_op, add_lhs, add_rhs) = div_lhs. kind
82
- && add_op. node == BinOpKind :: Add
83
- && let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = add_lhs. kind
81
+ if let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = inner_lhs. kind
82
+ && inner_op. node == BinOpKind :: Add
84
83
&& sub_op. node == BinOpKind :: Sub
85
84
&& check_literal ( sub_rhs)
86
85
&& check_eq_expr ( cx, sub_lhs, div_rhs)
87
86
{
88
- build_suggestion ( cx, expr, add_rhs , div_rhs, & mut applicability) ;
87
+ build_suggestion ( cx, expr, inner_rhs , div_rhs, & mut applicability) ;
89
88
return ;
90
89
}
91
90
92
91
// (x + y - 1) / y
93
- if let ExprKind :: Binary ( sub_op, sub_lhs, sub_rhs) = div_lhs. kind
94
- && sub_op. node == BinOpKind :: Sub
95
- && let ExprKind :: Binary ( add_op, add_lhs, add_rhs) = sub_lhs. kind
92
+ if let ExprKind :: Binary ( add_op, add_lhs, add_rhs) = inner_lhs. kind
93
+ && inner_op. node == BinOpKind :: Sub
96
94
&& add_op. node == BinOpKind :: Add
97
- && check_literal ( sub_rhs )
95
+ && check_literal ( inner_rhs )
98
96
&& check_eq_expr ( cx, add_rhs, div_rhs)
99
97
{
100
98
build_suggestion ( cx, expr, add_lhs, div_rhs, & mut applicability) ;
0 commit comments