Skip to content

Commit cf3f71d

Browse files
committed
Do not consider method call receiver as an argument in AST.
1 parent f719599 commit cf3f71d

File tree

6 files changed

+12
-12
lines changed

6 files changed

+12
-12
lines changed

clippy_lints/src/double_parens.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ impl EarlyLintPass for DoubleParens {
6161
}
6262
}
6363
},
64-
ExprKind::MethodCall(_, ref params, _) => {
65-
if params.len() == 2 {
66-
let param = &params[1];
64+
ExprKind::MethodCall(_, _, ref params, _) => {
65+
if let [ref param] = params[..] {
6766
if let ExprKind::Paren(_) = param.kind {
6867
span_lint(cx, DOUBLE_PARENS, param.span, msg);
6968
}

clippy_lints/src/option_env_unwrap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ declare_lint_pass!(OptionEnvUnwrap => [OPTION_ENV_UNWRAP]);
3737
impl EarlyLintPass for OptionEnvUnwrap {
3838
fn check_expr(&mut self, cx: &EarlyContext<'_>, expr: &Expr) {
3939
if_chain! {
40-
if let ExprKind::MethodCall(path_segment, args, _) = &expr.kind;
40+
if let ExprKind::MethodCall(path_segment, receiver, _, _) = &expr.kind;
4141
if matches!(path_segment.ident.name, sym::expect | sym::unwrap);
42-
if let ExprKind::Call(caller, _) = &args[0].kind;
42+
if let ExprKind::Call(caller, _) = &receiver.kind;
4343
if is_direct_expn_of(caller.span, "option_env").is_some();
4444
then {
4545
span_lint_and_help(

clippy_lints/src/precedence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,12 @@ impl EarlyLintPass for Precedence {
109109
let mut arg = operand;
110110

111111
let mut all_odd = true;
112-
while let ExprKind::MethodCall(path_segment, args, _) = &arg.kind {
112+
while let ExprKind::MethodCall(path_segment, receiver, _, _) = &arg.kind {
113113
let path_segment_str = path_segment.ident.name.as_str();
114114
all_odd &= ALLOWED_ODD_FUNCTIONS
115115
.iter()
116116
.any(|odd_function| **odd_function == *path_segment_str);
117-
arg = args.first().expect("A method always has a receiver.");
117+
arg = receiver;
118118
}
119119

120120
if_chain! {

clippy_lints/src/suspicious_operation_groupings.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ fn ident_difference_expr_with_base_location(
595595
| (Unary(_, _), Unary(_, _))
596596
| (Binary(_, _, _), Binary(_, _, _))
597597
| (Tup(_), Tup(_))
598-
| (MethodCall(_, _, _), MethodCall(_, _, _))
598+
| (MethodCall(_, _, _, _), MethodCall(_, _, _, _))
599599
| (Call(_, _), Call(_, _))
600600
| (ConstBlock(_), ConstBlock(_))
601601
| (Array(_), Array(_))

clippy_lints/src/unused_rounding.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,10 @@ declare_clippy_lint! {
3030
declare_lint_pass!(UnusedRounding => [UNUSED_ROUNDING]);
3131

3232
fn is_useless_rounding(expr: &Expr) -> Option<(&str, String)> {
33-
if let ExprKind::MethodCall(name_ident, args, _) = &expr.kind
33+
if let ExprKind::MethodCall(name_ident, receiver, _, _) = &expr.kind
3434
&& let method_name = name_ident.ident.name.as_str()
3535
&& (method_name == "ceil" || method_name == "round" || method_name == "floor")
36-
&& !args.is_empty()
37-
&& let ExprKind::Lit(spanned) = &args[0].kind
36+
&& let ExprKind::Lit(spanned) = &receiver.kind
3837
&& let LitKind::Float(symbol, ty) = spanned.kind {
3938
let f = symbol.as_str().parse::<f64>().unwrap();
4039
let f_str = symbol.to_string() + if let LitFloatType::Suffixed(ty) = ty {

clippy_utils/src/ast_utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ pub fn eq_expr(l: &Expr, r: &Expr) -> bool {
147147
(Array(l), Array(r)) | (Tup(l), Tup(r)) => over(l, r, |l, r| eq_expr(l, r)),
148148
(Repeat(le, ls), Repeat(re, rs)) => eq_expr(le, re) && eq_expr(&ls.value, &rs.value),
149149
(Call(lc, la), Call(rc, ra)) => eq_expr(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
150-
(MethodCall(lc, la, _), MethodCall(rc, ra, _)) => eq_path_seg(lc, rc) && over(la, ra, |l, r| eq_expr(l, r)),
150+
(MethodCall(lc, ls, la, _), MethodCall(rc, rs, ra, _)) => {
151+
eq_path_seg(lc, rc) && eq_expr(ls, rs) && over(la, ra, |l, r| eq_expr(l, r))
152+
},
151153
(Binary(lo, ll, lr), Binary(ro, rl, rr)) => lo.node == ro.node && eq_expr(ll, rl) && eq_expr(lr, rr),
152154
(Unary(lo, l), Unary(ro, r)) => mem::discriminant(lo) == mem::discriminant(ro) && eq_expr(l, r),
153155
(Lit(l), Lit(r)) => l.kind == r.kind,

0 commit comments

Comments
 (0)