Skip to content

Commit 236751d

Browse files
committed
Auto merge of rust-lang#13540 - GnomedDev:create-dir-single-arg, r=y21
Check MethodCall/Call arg count earlier or at all This gets rid of a bunch of possible panic spots, as well as bailing out earlier for optimisation reasons. I started doing this because I saw that a significant amount of time was being spent in the `create_dir` restriction lint when running clippy with `perf`, but this also helps with robustness. changelog: none
2 parents 04849bd + ef1db3f commit 236751d

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

+1-1
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

+1-1
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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)

clippy_lints/src/large_futures.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl_lint_pass!(LargeFuture => [LARGE_FUTURES]);
5757
impl<'tcx> LateLintPass<'tcx> for LargeFuture {
5858
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
5959
if let ExprKind::Match(scrutinee, _, MatchSource::AwaitDesugar) = expr.kind
60-
&& let ExprKind::Call(func, [arg, ..]) = scrutinee.kind
60+
&& let ExprKind::Call(func, [arg]) = scrutinee.kind
6161
&& let ExprKind::Path(QPath::LangItem(LangItem::IntoFutureIntoFuture, ..)) = func.kind
6262
&& !expr.span.from_expansion()
6363
&& let ty = cx.typeck_results().expr_ty(arg)

clippy_lints/src/len_zero.rs

+3-15
Original file line numberDiff line numberDiff line change
@@ -517,37 +517,25 @@ fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>
517517
return;
518518
}
519519

520-
if let (&ExprKind::MethodCall(method_path, receiver, args, _), ExprKind::Lit(lit)) = (&method.kind, &lit.kind) {
520+
if let (&ExprKind::MethodCall(method_path, receiver, [], _), ExprKind::Lit(lit)) = (&method.kind, &lit.kind) {
521521
// check if we are in an is_empty() method
522522
if let Some(name) = get_item_name(cx, method) {
523523
if name.as_str() == "is_empty" {
524524
return;
525525
}
526526
}
527527

528-
check_len(
529-
cx,
530-
span,
531-
method_path.ident.name,
532-
receiver,
533-
args,
534-
&lit.node,
535-
op,
536-
compare_to,
537-
);
528+
check_len(cx, span, method_path.ident.name, receiver, &lit.node, op, compare_to);
538529
} else {
539530
check_empty_expr(cx, span, method, lit, op);
540531
}
541532
}
542533

543-
// FIXME(flip1995): Figure out how to reduce the number of arguments
544-
#[allow(clippy::too_many_arguments)]
545534
fn check_len(
546535
cx: &LateContext<'_>,
547536
span: Span,
548537
method_name: Symbol,
549538
receiver: &Expr<'_>,
550-
args: &[Expr<'_>],
551539
lit: &LitKind,
552540
op: &str,
553541
compare_to: u32,
@@ -558,7 +546,7 @@ fn check_len(
558546
return;
559547
}
560548

561-
if method_name == sym::len && args.is_empty() && has_is_empty(cx, receiver) {
549+
if method_name == sym::len && has_is_empty(cx, receiver) {
562550
let mut applicability = Applicability::MachineApplicable;
563551
span_lint_and_sugg(
564552
cx,

clippy_lints/src/loops/manual_while_let_some.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ fn report_lint(cx: &LateContext<'_>, pop_span: Span, pop_stmt_kind: PopStmt<'_>,
4747
);
4848
}
4949

50-
fn match_method_call(cx: &LateContext<'_>, expr: &Expr<'_>, method: Symbol) -> bool {
51-
if let ExprKind::MethodCall(..) = expr.kind
50+
fn match_method_call<const ARGS_COUNT: usize>(cx: &LateContext<'_>, expr: &Expr<'_>, method: Symbol) -> bool {
51+
if let ExprKind::MethodCall(_, _, args, _) = expr.kind
52+
&& args.len() == ARGS_COUNT
5253
&& let Some(id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
5354
{
5455
cx.tcx.is_diagnostic_item(method, id)
@@ -58,9 +59,9 @@ fn match_method_call(cx: &LateContext<'_>, expr: &Expr<'_>, method: Symbol) -> b
5859
}
5960

6061
fn is_vec_pop_unwrap(cx: &LateContext<'_>, expr: &Expr<'_>, is_empty_recv: &Expr<'_>) -> bool {
61-
if (match_method_call(cx, expr, sym::option_unwrap) || match_method_call(cx, expr, sym::option_expect))
62+
if (match_method_call::<0>(cx, expr, sym::option_unwrap) || match_method_call::<1>(cx, expr, sym::option_expect))
6263
&& let ExprKind::MethodCall(_, unwrap_recv, ..) = expr.kind
63-
&& match_method_call(cx, unwrap_recv, sym::vec_pop)
64+
&& match_method_call::<0>(cx, unwrap_recv, sym::vec_pop)
6465
&& let ExprKind::MethodCall(_, pop_recv, ..) = unwrap_recv.kind
6566
{
6667
// make sure they're the same `Vec`
@@ -96,7 +97,7 @@ fn check_call_arguments(cx: &LateContext<'_>, stmt: &Stmt<'_>, is_empty_recv: &E
9697
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, full_cond: &'tcx Expr<'_>, body: &'tcx Expr<'_>, loop_span: Span) {
9798
if let ExprKind::Unary(UnOp::Not, cond) = full_cond.kind
9899
&& let ExprKind::MethodCall(_, is_empty_recv, _, _) = cond.kind
99-
&& match_method_call(cx, cond, sym::vec_is_empty)
100+
&& match_method_call::<0>(cx, cond, sym::vec_is_empty)
100101
&& let ExprKind::Block(body, _) = body.kind
101102
&& let Some(stmt) = body.stmts.first()
102103
{

clippy_lints/src/loops/same_item_push.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,8 @@ fn get_vec_push<'tcx>(
172172
stmt: &'tcx Stmt<'_>,
173173
) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, SyntaxContext)> {
174174
if let StmtKind::Semi(semi_stmt) = &stmt.kind
175-
// Extract method being called
176-
&& let ExprKind::MethodCall(path, self_expr, args, _) = &semi_stmt.kind
177-
// Figure out the parameters for the method call
178-
&& let Some(pushed_item) = args.first()
175+
// Extract method being called and figure out the parameters for the method call
176+
&& let ExprKind::MethodCall(path, self_expr, [pushed_item], _) = &semi_stmt.kind
179177
// Check that the method being called is push() on a Vec
180178
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::Vec)
181179
&& path.ident.name.as_str() == "push"

clippy_lints/src/main_recursion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl LateLintPass<'_> for MainRecursion {
4242
return;
4343
}
4444

45-
if let ExprKind::Call(func, _) = &expr.kind
45+
if let ExprKind::Call(func, []) = &expr.kind
4646
&& let ExprKind::Path(QPath::Resolved(_, path)) = &func.kind
4747
&& let Some(def_id) = path.res.opt_def_id()
4848
&& is_entrypoint_fn(cx, def_id)

clippy_lints/src/manual_bits.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ fn get_one_size_of_ty<'tcx>(
9595
}
9696

9797
fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<(&'tcx rustc_hir::Ty<'tcx>, Ty<'tcx>)> {
98-
if let ExprKind::Call(count_func, _func_args) = expr.kind
98+
if let ExprKind::Call(count_func, []) = expr.kind
9999
&& let ExprKind::Path(ref count_func_qpath) = count_func.kind
100100
&& let QPath::Resolved(_, count_func_path) = count_func_qpath
101101
&& let Some(segment_zero) = count_func_path.segments.first()

clippy_lints/src/manual_is_power_of_two.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl LateLintPass<'_> for ManualIsPowerOfTwo {
4141
&& bin_op.node == BinOpKind::Eq
4242
{
4343
// a.count_ones() == 1
44-
if let ExprKind::MethodCall(method_name, reciever, _, _) = left.kind
44+
if let ExprKind::MethodCall(method_name, reciever, [], _) = left.kind
4545
&& method_name.ident.as_str() == "count_ones"
4646
&& let &Uint(_) = cx.typeck_results().expr_ty(reciever).kind()
4747
&& check_lit(right, 1)
@@ -50,7 +50,7 @@ impl LateLintPass<'_> for ManualIsPowerOfTwo {
5050
}
5151

5252
// 1 == a.count_ones()
53-
if let ExprKind::MethodCall(method_name, reciever, _, _) = right.kind
53+
if let ExprKind::MethodCall(method_name, reciever, [], _) = right.kind
5454
&& method_name.ident.as_str() == "count_ones"
5555
&& let &Uint(_) = cx.typeck_results().expr_ty(reciever).kind()
5656
&& check_lit(left, 1)

clippy_lints/src/manual_slice_size_calculation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ fn simplify_half<'tcx>(
8383
) -> Option<&'tcx Expr<'tcx>> {
8484
if !expr1.span.from_expansion()
8585
// expr1 is `[T1].len()`?
86-
&& let ExprKind::MethodCall(method_path, receiver, _, _) = expr1.kind
86+
&& let ExprKind::MethodCall(method_path, receiver, [], _) = expr1.kind
8787
&& method_path.ident.name == sym::len
8888
&& let receiver_ty = cx.typeck_results().expr_ty(receiver)
8989
&& let ty::Slice(ty1) = receiver_ty.peel_refs().kind()
9090
// expr2 is `size_of::<T2>()`?
91-
&& let ExprKind::Call(func, _) = expr2.kind
91+
&& let ExprKind::Call(func, []) = expr2.kind
9292
&& let ExprKind::Path(ref func_qpath) = func.kind
9393
&& let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id()
9494
&& cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id)

clippy_lints/src/manual_string_new.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ impl LateLintPass<'_> for ManualStringNew {
5252
}
5353

5454
match expr.kind {
55-
ExprKind::Call(func, args) => {
56-
parse_call(cx, expr.span, func, args);
55+
ExprKind::Call(func, [arg]) => {
56+
parse_call(cx, expr.span, func, arg);
5757
},
5858
ExprKind::MethodCall(path_segment, receiver, ..) => {
5959
parse_method_call(cx, expr.span, path_segment, receiver);
@@ -93,20 +93,15 @@ fn parse_method_call(cx: &LateContext<'_>, span: Span, path_segment: &PathSegmen
9393
let method_arg_kind = &receiver.kind;
9494
if ["to_string", "to_owned", "into"].contains(&ident) && is_expr_kind_empty_str(method_arg_kind) {
9595
warn_then_suggest(cx, span);
96-
} else if let ExprKind::Call(func, args) = method_arg_kind {
96+
} else if let ExprKind::Call(func, [arg]) = method_arg_kind {
9797
// If our first argument is a function call itself, it could be an `unwrap`-like function.
9898
// E.g. String::try_from("hello").unwrap(), TryFrom::try_from("").expect("hello"), etc.
99-
parse_call(cx, span, func, args);
99+
parse_call(cx, span, func, arg);
100100
}
101101
}
102102

103103
/// Tries to parse an expression as a function call, emitting the warning if necessary.
104-
fn parse_call(cx: &LateContext<'_>, span: Span, func: &Expr<'_>, args: &[Expr<'_>]) {
105-
if args.len() != 1 {
106-
return;
107-
}
108-
109-
let arg_kind = &args[0].kind;
104+
fn parse_call(cx: &LateContext<'_>, span: Span, func: &Expr<'_>, arg: &Expr<'_>) {
110105
if let ExprKind::Path(qpath) = &func.kind {
111106
// String::from(...) or String::try_from(...)
112107
if let QPath::TypeRelative(ty, path_seg) = qpath
@@ -115,13 +110,13 @@ fn parse_call(cx: &LateContext<'_>, span: Span, func: &Expr<'_>, args: &[Expr<'_
115110
&& let QPath::Resolved(_, path) = qpath
116111
&& let [path_seg] = path.segments
117112
&& path_seg.ident.name == sym::String
118-
&& is_expr_kind_empty_str(arg_kind)
113+
&& is_expr_kind_empty_str(&arg.kind)
119114
{
120115
warn_then_suggest(cx, span);
121116
} else if let QPath::Resolved(_, path) = qpath {
122117
// From::from(...) or TryFrom::try_from(...)
123118
if let [path_seg1, path_seg2] = path.segments
124-
&& is_expr_kind_empty_str(arg_kind)
119+
&& is_expr_kind_empty_str(&arg.kind)
125120
&& ((path_seg1.ident.name == sym::From && path_seg2.ident.name == sym::from)
126121
|| (path_seg1.ident.name == sym::TryFrom && path_seg2.ident.name == sym::try_from))
127122
{

clippy_lints/src/matches/redundant_pattern_match.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn find_method_sugg_for_if_let<'tcx>(
210210

211211
// check that `while_let_on_iterator` lint does not trigger
212212
if keyword == "while"
213-
&& let ExprKind::MethodCall(method_path, ..) = let_expr.kind
213+
&& let ExprKind::MethodCall(method_path, _, [], _) = let_expr.kind
214214
&& method_path.ident.name == sym::next
215215
&& is_trait_method(cx, let_expr, sym::Iterator)
216216
{

clippy_lints/src/matches/try_err.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
2121
// #[allow(unreachable_code)]
2222
// val,
2323
// };
24-
if let ExprKind::Call(match_fun, [try_arg, ..]) = scrutinee.kind
24+
if let ExprKind::Call(match_fun, [try_arg]) = scrutinee.kind
2525
&& let ExprKind::Path(ref match_fun_path) = match_fun.kind
2626
&& matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, ..))
27-
&& let ExprKind::Call(err_fun, [err_arg, ..]) = try_arg.kind
27+
&& let ExprKind::Call(err_fun, [err_arg]) = try_arg.kind
2828
&& is_res_lang_ctor(cx, path_res(cx, err_fun), ResultErr)
2929
&& let Some(return_ty) = find_return_type(cx, &expr.kind)
3030
{

clippy_lints/src/methods/clone_on_copy.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(super) fn check(
5858
return;
5959
},
6060
// ? is a Call, makes sure not to rec *x?, but rather (*x)?
61-
ExprKind::Call(hir_callee, _) => matches!(
61+
ExprKind::Call(hir_callee, [_]) => matches!(
6262
hir_callee.kind,
6363
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, ..))
6464
),

clippy_lints/src/methods/iter_filter.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ fn is_method(
106106

107107
fn parent_is_map(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
108108
if let Some(expr) = get_parent_expr(cx, expr)
109-
&& is_trait_method(cx, expr, sym::Iterator)
110-
&& let ExprKind::MethodCall(path, _, _, _) = expr.kind
109+
&& let ExprKind::MethodCall(path, _, [_], _) = expr.kind
111110
&& path.ident.name == sym::map
111+
&& is_trait_method(cx, expr, sym::Iterator)
112112
{
113113
return true;
114114
}

clippy_lints/src/methods/manual_c_str_literals.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args
8787

8888
/// Checks `CStr::from_ptr(b"foo\0".as_ptr().cast())`
8989
fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) {
90-
if let ExprKind::MethodCall(method, lit, ..) = peel_ptr_cast(arg).kind
90+
if let ExprKind::MethodCall(method, lit, [], _) = peel_ptr_cast(arg).kind
9191
&& method.ident.name == sym::as_ptr
9292
&& !lit.span.from_expansion()
9393
&& let ExprKind::Lit(lit) = lit.kind

clippy_lints/src/methods/manual_saturating_arithmetic.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ enum MinMax {
6868

6969
fn is_min_or_max(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<MinMax> {
7070
// `T::max_value()` `T::min_value()` inherent methods
71-
if let hir::ExprKind::Call(func, args) = &expr.kind
72-
&& args.is_empty()
71+
if let hir::ExprKind::Call(func, []) = &expr.kind
7372
&& let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind
7473
{
7574
match segment.ident.as_str() {

clippy_lints/src/methods/map_clone.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,8 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
8686
}
8787
}
8888
},
89-
hir::ExprKind::Call(call, args) => {
89+
hir::ExprKind::Call(call, [arg]) => {
9090
if let hir::ExprKind::Path(qpath) = call.kind
91-
&& let [arg] = args
9291
&& ident_eq(name, arg)
9392
{
9493
handle_path(cx, call, &qpath, e, recv);

0 commit comments

Comments
 (0)