Skip to content

Commit ef1db3f

Browse files
committed
Check MethodCall/Call arg count earlier or at all
1 parent 05f3793 commit ef1db3f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+127
-149
lines changed

clippy_lints/src/box_default.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ impl LateLintPass<'_> for BoxDefault {
4747
// And the call is that of a `Box` method
4848
&& path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
4949
// And the single argument to the call is another function call
50-
// This is the `T::default()` of `Box::new(T::default())`
50+
// This is the `T::default()` (or default equivalent) of `Box::new(T::default())`
5151
&& let ExprKind::Call(arg_path, _) = arg.kind
5252
// And we are not in a foreign crate's macro
5353
&& !in_external_macro(cx.sess(), expr.span)

clippy_lints/src/casts/cast_abs_to_unsigned.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(super) fn check(
1919
if msrv.meets(msrvs::UNSIGNED_ABS)
2020
&& let ty::Int(from) = cast_from.kind()
2121
&& let ty::Uint(to) = cast_to.kind()
22-
&& let ExprKind::MethodCall(method_path, receiver, ..) = cast_expr.kind
22+
&& let ExprKind::MethodCall(method_path, receiver, [], _) = cast_expr.kind
2323
&& method_path.ident.name.as_str() == "abs"
2424
{
2525
let span = if from.bit_width() == to.bit_width() {

clippy_lints/src/casts/cast_ptr_alignment.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
1919
cx.typeck_results().expr_ty(expr),
2020
);
2121
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
22-
} else if let ExprKind::MethodCall(method_path, self_arg, ..) = &expr.kind {
22+
} else if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind {
2323
if method_path.ident.name == sym!(cast)
2424
&& let Some(generic_args) = method_path.args
2525
&& let [GenericArg::Type(cast_to)] = generic_args.args

clippy_lints/src/create_dir.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ declare_lint_pass!(CreateDir => [CREATE_DIR]);
3434

3535
impl LateLintPass<'_> for CreateDir {
3636
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
37-
if let ExprKind::Call(func, [arg, ..]) = expr.kind
37+
if let ExprKind::Call(func, [arg]) = expr.kind
3838
&& let ExprKind::Path(ref path) = func.kind
3939
&& let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id()
4040
&& cx.tcx.is_diagnostic_item(sym::fs_create_dir, def_id)

clippy_lints/src/default.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
8383
if !expr.span.from_expansion()
8484
// Avoid cases already linted by `field_reassign_with_default`
8585
&& !self.reassigned_linted.contains(&expr.span)
86-
&& let ExprKind::Call(path, ..) = expr.kind
86+
&& let ExprKind::Call(path, []) = expr.kind
8787
&& !in_automatically_derived(cx.tcx, expr.hir_id)
8888
&& let ExprKind::Path(ref qpath) = path.kind
8989
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
@@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
253253

254254
/// Checks if the given expression is the `default` method belonging to the `Default` trait.
255255
fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool {
256-
if let ExprKind::Call(fn_expr, _) = &expr.kind
256+
if let ExprKind::Call(fn_expr, []) = &expr.kind
257257
&& let ExprKind::Path(qpath) = &fn_expr.kind
258258
&& let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id)
259259
{

clippy_lints/src/exit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ declare_lint_pass!(Exit => [EXIT]);
4343

4444
impl<'tcx> LateLintPass<'tcx> for Exit {
4545
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
46-
if let ExprKind::Call(path_expr, _args) = e.kind
46+
if let ExprKind::Call(path_expr, [_]) = e.kind
4747
&& let ExprKind::Path(ref path) = path_expr.kind
4848
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
4949
&& cx.tcx.is_diagnostic_item(sym::process_exit, def_id)

clippy_lints/src/explicit_write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
5757
&& unwrap_fun.ident.name == sym::unwrap
5858
// match call to write_fmt
5959
&& let ExprKind::MethodCall(write_fun, write_recv, [write_arg], _) = *look_in_block(cx, &write_call.kind)
60-
&& let ExprKind::Call(write_recv_path, _) = write_recv.kind
60+
&& let ExprKind::Call(write_recv_path, []) = write_recv.kind
6161
&& write_fun.ident.name == sym!(write_fmt)
6262
&& let Some(def_id) = path_def_id(cx, write_recv_path)
6363
{

clippy_lints/src/floating_point_arithmetic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,12 +436,12 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
436436
lhs,
437437
rhs,
438438
) = expr.kind
439+
&& let ExprKind::MethodCall(path, self_arg, [], _) = &lhs.kind
440+
&& path.ident.name.as_str() == "exp"
439441
&& cx.typeck_results().expr_ty(lhs).is_floating_point()
440442
&& let Some(value) = ConstEvalCtxt::new(cx).eval(rhs)
441443
&& (F32(1.0) == value || F64(1.0) == value)
442-
&& let ExprKind::MethodCall(path, self_arg, ..) = &lhs.kind
443444
&& cx.typeck_results().expr_ty(self_arg).is_floating_point()
444-
&& path.ident.name.as_str() == "exp"
445445
{
446446
span_lint_and_sugg(
447447
cx,

clippy_lints/src/format_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ struct FormatImplExpr<'a, 'tcx> {
151151
impl FormatImplExpr<'_, '_> {
152152
fn check_to_string_in_display(&self) {
153153
if self.format_trait_impl.name == sym::Display
154-
&& let ExprKind::MethodCall(path, self_arg, ..) = self.expr.kind
154+
&& let ExprKind::MethodCall(path, self_arg, [], _) = self.expr.kind
155155
// Get the hir_id of the object we are calling the method on
156156
// Is the method to_string() ?
157157
&& path.ident.name == sym::to_string

clippy_lints/src/if_let_mutex.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn mutex_lock_call<'tcx>(
8282
expr: &'tcx Expr<'_>,
8383
op_mutex: Option<&'tcx Expr<'_>>,
8484
) -> ControlFlow<&'tcx Expr<'tcx>> {
85-
if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind
85+
if let ExprKind::MethodCall(path, self_arg, [], _) = &expr.kind
8686
&& path.ident.as_str() == "lock"
8787
&& let ty = cx.typeck_results().expr_ty(self_arg).peel_refs()
8888
&& is_type_diagnostic_item(cx, ty, sym::Mutex)

0 commit comments

Comments
 (0)