Skip to content

Commit

Permalink
Auto merge of #13540 - GnomedDev:create-dir-single-arg, r=y21
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Oct 13, 2024
2 parents 04849bd + ef1db3f commit 236751d
Show file tree
Hide file tree
Showing 59 changed files with 127 additions and 149 deletions.
2 changes: 1 addition & 1 deletion clippy_lints/src/box_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl LateLintPass<'_> for BoxDefault {
// And the call is that of a `Box` method
&& path_def_id(cx, ty).map_or(false, |id| Some(id) == cx.tcx.lang_items().owned_box())
// And the single argument to the call is another function call
// This is the `T::default()` of `Box::new(T::default())`
// This is the `T::default()` (or default equivalent) of `Box::new(T::default())`
&& let ExprKind::Call(arg_path, _) = arg.kind
// And we are not in a foreign crate's macro
&& !in_external_macro(cx.sess(), expr.span)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/cast_abs_to_unsigned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(super) fn check(
if msrv.meets(msrvs::UNSIGNED_ABS)
&& let ty::Int(from) = cast_from.kind()
&& let ty::Uint(to) = cast_to.kind()
&& let ExprKind::MethodCall(method_path, receiver, ..) = cast_expr.kind
&& let ExprKind::MethodCall(method_path, receiver, [], _) = cast_expr.kind
&& method_path.ident.name.as_str() == "abs"
{
let span = if from.bit_width() == to.bit_width() {
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/casts/cast_ptr_alignment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
cx.typeck_results().expr_ty(expr),
);
lint_cast_ptr_alignment(cx, expr, cast_from, cast_to);
} else if let ExprKind::MethodCall(method_path, self_arg, ..) = &expr.kind {
} else if let ExprKind::MethodCall(method_path, self_arg, [], _) = &expr.kind {
if method_path.ident.name == sym!(cast)
&& let Some(generic_args) = method_path.args
&& let [GenericArg::Type(cast_to)] = generic_args.args
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/create_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ declare_lint_pass!(CreateDir => [CREATE_DIR]);

impl LateLintPass<'_> for CreateDir {
fn check_expr(&mut self, cx: &LateContext<'_>, expr: &Expr<'_>) {
if let ExprKind::Call(func, [arg, ..]) = expr.kind
if let ExprKind::Call(func, [arg]) = expr.kind
&& let ExprKind::Path(ref path) = func.kind
&& let Some(def_id) = cx.qpath_res(path, func.hir_id).opt_def_id()
&& cx.tcx.is_diagnostic_item(sym::fs_create_dir, def_id)
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {
if !expr.span.from_expansion()
// Avoid cases already linted by `field_reassign_with_default`
&& !self.reassigned_linted.contains(&expr.span)
&& let ExprKind::Call(path, ..) = expr.kind
&& let ExprKind::Call(path, []) = expr.kind
&& !in_automatically_derived(cx.tcx, expr.hir_id)
&& let ExprKind::Path(ref qpath) = path.kind
&& let Some(def_id) = cx.qpath_res(qpath, path.hir_id).opt_def_id()
Expand Down Expand Up @@ -253,7 +253,7 @@ impl<'tcx> LateLintPass<'tcx> for Default {

/// Checks if the given expression is the `default` method belonging to the `Default` trait.
fn is_expr_default<'tcx>(expr: &'tcx Expr<'tcx>, cx: &LateContext<'tcx>) -> bool {
if let ExprKind::Call(fn_expr, _) = &expr.kind
if let ExprKind::Call(fn_expr, []) = &expr.kind
&& let ExprKind::Path(qpath) = &fn_expr.kind
&& let Res::Def(_, def_id) = cx.qpath_res(qpath, fn_expr.hir_id)
{
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/exit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ declare_lint_pass!(Exit => [EXIT]);

impl<'tcx> LateLintPass<'tcx> for Exit {
fn check_expr(&mut self, cx: &LateContext<'tcx>, e: &'tcx Expr<'_>) {
if let ExprKind::Call(path_expr, _args) = e.kind
if let ExprKind::Call(path_expr, [_]) = e.kind
&& let ExprKind::Path(ref path) = path_expr.kind
&& let Some(def_id) = cx.qpath_res(path, path_expr.hir_id).opt_def_id()
&& cx.tcx.is_diagnostic_item(sym::process_exit, def_id)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/explicit_write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for ExplicitWrite {
&& unwrap_fun.ident.name == sym::unwrap
// match call to write_fmt
&& let ExprKind::MethodCall(write_fun, write_recv, [write_arg], _) = *look_in_block(cx, &write_call.kind)
&& let ExprKind::Call(write_recv_path, _) = write_recv.kind
&& let ExprKind::Call(write_recv_path, []) = write_recv.kind
&& write_fun.ident.name == sym!(write_fmt)
&& let Some(def_id) = path_def_id(cx, write_recv_path)
{
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/floating_point_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,12 +436,12 @@ fn check_expm1(cx: &LateContext<'_>, expr: &Expr<'_>) {
lhs,
rhs,
) = expr.kind
&& let ExprKind::MethodCall(path, self_arg, [], _) = &lhs.kind
&& path.ident.name.as_str() == "exp"
&& cx.typeck_results().expr_ty(lhs).is_floating_point()
&& let Some(value) = ConstEvalCtxt::new(cx).eval(rhs)
&& (F32(1.0) == value || F64(1.0) == value)
&& let ExprKind::MethodCall(path, self_arg, ..) = &lhs.kind
&& cx.typeck_results().expr_ty(self_arg).is_floating_point()
&& path.ident.name.as_str() == "exp"
{
span_lint_and_sugg(
cx,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/format_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ struct FormatImplExpr<'a, 'tcx> {
impl FormatImplExpr<'_, '_> {
fn check_to_string_in_display(&self) {
if self.format_trait_impl.name == sym::Display
&& let ExprKind::MethodCall(path, self_arg, ..) = self.expr.kind
&& let ExprKind::MethodCall(path, self_arg, [], _) = self.expr.kind
// Get the hir_id of the object we are calling the method on
// Is the method to_string() ?
&& path.ident.name == sym::to_string
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/if_let_mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ fn mutex_lock_call<'tcx>(
expr: &'tcx Expr<'_>,
op_mutex: Option<&'tcx Expr<'_>>,
) -> ControlFlow<&'tcx Expr<'tcx>> {
if let ExprKind::MethodCall(path, self_arg, ..) = &expr.kind
if let ExprKind::MethodCall(path, self_arg, [], _) = &expr.kind
&& path.ident.as_str() == "lock"
&& let ty = cx.typeck_results().expr_ty(self_arg).peel_refs()
&& is_type_diagnostic_item(cx, ty, sym::Mutex)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/large_futures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl_lint_pass!(LargeFuture => [LARGE_FUTURES]);
impl<'tcx> LateLintPass<'tcx> for LargeFuture {
fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
if let ExprKind::Match(scrutinee, _, MatchSource::AwaitDesugar) = expr.kind
&& let ExprKind::Call(func, [arg, ..]) = scrutinee.kind
&& let ExprKind::Call(func, [arg]) = scrutinee.kind
&& let ExprKind::Path(QPath::LangItem(LangItem::IntoFutureIntoFuture, ..)) = func.kind
&& !expr.span.from_expansion()
&& let ty = cx.typeck_results().expr_ty(arg)
Expand Down
18 changes: 3 additions & 15 deletions clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -517,37 +517,25 @@ fn check_cmp(cx: &LateContext<'_>, span: Span, method: &Expr<'_>, lit: &Expr<'_>
return;
}

if let (&ExprKind::MethodCall(method_path, receiver, args, _), ExprKind::Lit(lit)) = (&method.kind, &lit.kind) {
if let (&ExprKind::MethodCall(method_path, receiver, [], _), ExprKind::Lit(lit)) = (&method.kind, &lit.kind) {
// check if we are in an is_empty() method
if let Some(name) = get_item_name(cx, method) {
if name.as_str() == "is_empty" {
return;
}
}

check_len(
cx,
span,
method_path.ident.name,
receiver,
args,
&lit.node,
op,
compare_to,
);
check_len(cx, span, method_path.ident.name, receiver, &lit.node, op, compare_to);
} else {
check_empty_expr(cx, span, method, lit, op);
}
}

// FIXME(flip1995): Figure out how to reduce the number of arguments
#[allow(clippy::too_many_arguments)]
fn check_len(
cx: &LateContext<'_>,
span: Span,
method_name: Symbol,
receiver: &Expr<'_>,
args: &[Expr<'_>],
lit: &LitKind,
op: &str,
compare_to: u32,
Expand All @@ -558,7 +546,7 @@ fn check_len(
return;
}

if method_name == sym::len && args.is_empty() && has_is_empty(cx, receiver) {
if method_name == sym::len && has_is_empty(cx, receiver) {
let mut applicability = Applicability::MachineApplicable;
span_lint_and_sugg(
cx,
Expand Down
11 changes: 6 additions & 5 deletions clippy_lints/src/loops/manual_while_let_some.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ fn report_lint(cx: &LateContext<'_>, pop_span: Span, pop_stmt_kind: PopStmt<'_>,
);
}

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

fn is_vec_pop_unwrap(cx: &LateContext<'_>, expr: &Expr<'_>, is_empty_recv: &Expr<'_>) -> bool {
if (match_method_call(cx, expr, sym::option_unwrap) || match_method_call(cx, expr, sym::option_expect))
if (match_method_call::<0>(cx, expr, sym::option_unwrap) || match_method_call::<1>(cx, expr, sym::option_expect))
&& let ExprKind::MethodCall(_, unwrap_recv, ..) = expr.kind
&& match_method_call(cx, unwrap_recv, sym::vec_pop)
&& match_method_call::<0>(cx, unwrap_recv, sym::vec_pop)
&& let ExprKind::MethodCall(_, pop_recv, ..) = unwrap_recv.kind
{
// make sure they're the same `Vec`
Expand Down Expand Up @@ -96,7 +97,7 @@ fn check_call_arguments(cx: &LateContext<'_>, stmt: &Stmt<'_>, is_empty_recv: &E
pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, full_cond: &'tcx Expr<'_>, body: &'tcx Expr<'_>, loop_span: Span) {
if let ExprKind::Unary(UnOp::Not, cond) = full_cond.kind
&& let ExprKind::MethodCall(_, is_empty_recv, _, _) = cond.kind
&& match_method_call(cx, cond, sym::vec_is_empty)
&& match_method_call::<0>(cx, cond, sym::vec_is_empty)
&& let ExprKind::Block(body, _) = body.kind
&& let Some(stmt) = body.stmts.first()
{
Expand Down
6 changes: 2 additions & 4 deletions clippy_lints/src/loops/same_item_push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,8 @@ fn get_vec_push<'tcx>(
stmt: &'tcx Stmt<'_>,
) -> Option<(&'tcx Expr<'tcx>, &'tcx Expr<'tcx>, SyntaxContext)> {
if let StmtKind::Semi(semi_stmt) = &stmt.kind
// Extract method being called
&& let ExprKind::MethodCall(path, self_expr, args, _) = &semi_stmt.kind
// Figure out the parameters for the method call
&& let Some(pushed_item) = args.first()
// Extract method being called and figure out the parameters for the method call
&& let ExprKind::MethodCall(path, self_expr, [pushed_item], _) = &semi_stmt.kind
// Check that the method being called is push() on a Vec
&& is_type_diagnostic_item(cx, cx.typeck_results().expr_ty(self_expr), sym::Vec)
&& path.ident.name.as_str() == "push"
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/main_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl LateLintPass<'_> for MainRecursion {
return;
}

if let ExprKind::Call(func, _) = &expr.kind
if let ExprKind::Call(func, []) = &expr.kind
&& let ExprKind::Path(QPath::Resolved(_, path)) = &func.kind
&& let Some(def_id) = path.res.opt_def_id()
&& is_entrypoint_fn(cx, def_id)
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/manual_bits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fn get_one_size_of_ty<'tcx>(
}

fn get_size_of_ty<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) -> Option<(&'tcx rustc_hir::Ty<'tcx>, Ty<'tcx>)> {
if let ExprKind::Call(count_func, _func_args) = expr.kind
if let ExprKind::Call(count_func, []) = expr.kind
&& let ExprKind::Path(ref count_func_qpath) = count_func.kind
&& let QPath::Resolved(_, count_func_path) = count_func_qpath
&& let Some(segment_zero) = count_func_path.segments.first()
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/manual_is_power_of_two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl LateLintPass<'_> for ManualIsPowerOfTwo {
&& bin_op.node == BinOpKind::Eq
{
// a.count_ones() == 1
if let ExprKind::MethodCall(method_name, reciever, _, _) = left.kind
if let ExprKind::MethodCall(method_name, reciever, [], _) = left.kind
&& method_name.ident.as_str() == "count_ones"
&& let &Uint(_) = cx.typeck_results().expr_ty(reciever).kind()
&& check_lit(right, 1)
Expand All @@ -50,7 +50,7 @@ impl LateLintPass<'_> for ManualIsPowerOfTwo {
}

// 1 == a.count_ones()
if let ExprKind::MethodCall(method_name, reciever, _, _) = right.kind
if let ExprKind::MethodCall(method_name, reciever, [], _) = right.kind
&& method_name.ident.as_str() == "count_ones"
&& let &Uint(_) = cx.typeck_results().expr_ty(reciever).kind()
&& check_lit(left, 1)
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/manual_slice_size_calculation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ fn simplify_half<'tcx>(
) -> Option<&'tcx Expr<'tcx>> {
if !expr1.span.from_expansion()
// expr1 is `[T1].len()`?
&& let ExprKind::MethodCall(method_path, receiver, _, _) = expr1.kind
&& let ExprKind::MethodCall(method_path, receiver, [], _) = expr1.kind
&& method_path.ident.name == sym::len
&& let receiver_ty = cx.typeck_results().expr_ty(receiver)
&& let ty::Slice(ty1) = receiver_ty.peel_refs().kind()
// expr2 is `size_of::<T2>()`?
&& let ExprKind::Call(func, _) = expr2.kind
&& let ExprKind::Call(func, []) = expr2.kind
&& let ExprKind::Path(ref func_qpath) = func.kind
&& let Some(def_id) = cx.qpath_res(func_qpath, func.hir_id).opt_def_id()
&& cx.tcx.is_diagnostic_item(sym::mem_size_of, def_id)
Expand Down
19 changes: 7 additions & 12 deletions clippy_lints/src/manual_string_new.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ impl LateLintPass<'_> for ManualStringNew {
}

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

/// Tries to parse an expression as a function call, emitting the warning if necessary.
fn parse_call(cx: &LateContext<'_>, span: Span, func: &Expr<'_>, args: &[Expr<'_>]) {
if args.len() != 1 {
return;
}

let arg_kind = &args[0].kind;
fn parse_call(cx: &LateContext<'_>, span: Span, func: &Expr<'_>, arg: &Expr<'_>) {
if let ExprKind::Path(qpath) = &func.kind {
// String::from(...) or String::try_from(...)
if let QPath::TypeRelative(ty, path_seg) = qpath
Expand All @@ -115,13 +110,13 @@ fn parse_call(cx: &LateContext<'_>, span: Span, func: &Expr<'_>, args: &[Expr<'_
&& let QPath::Resolved(_, path) = qpath
&& let [path_seg] = path.segments
&& path_seg.ident.name == sym::String
&& is_expr_kind_empty_str(arg_kind)
&& is_expr_kind_empty_str(&arg.kind)
{
warn_then_suggest(cx, span);
} else if let QPath::Resolved(_, path) = qpath {
// From::from(...) or TryFrom::try_from(...)
if let [path_seg1, path_seg2] = path.segments
&& is_expr_kind_empty_str(arg_kind)
&& is_expr_kind_empty_str(&arg.kind)
&& ((path_seg1.ident.name == sym::From && path_seg2.ident.name == sym::from)
|| (path_seg1.ident.name == sym::TryFrom && path_seg2.ident.name == sym::try_from))
{
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches/redundant_pattern_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn find_method_sugg_for_if_let<'tcx>(

// check that `while_let_on_iterator` lint does not trigger
if keyword == "while"
&& let ExprKind::MethodCall(method_path, ..) = let_expr.kind
&& let ExprKind::MethodCall(method_path, _, [], _) = let_expr.kind
&& method_path.ident.name == sym::next
&& is_trait_method(cx, let_expr, sym::Iterator)
{
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/matches/try_err.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ pub(super) fn check<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, scrutine
// #[allow(unreachable_code)]
// val,
// };
if let ExprKind::Call(match_fun, [try_arg, ..]) = scrutinee.kind
if let ExprKind::Call(match_fun, [try_arg]) = scrutinee.kind
&& let ExprKind::Path(ref match_fun_path) = match_fun.kind
&& matches!(match_fun_path, QPath::LangItem(LangItem::TryTraitBranch, ..))
&& let ExprKind::Call(err_fun, [err_arg, ..]) = try_arg.kind
&& let ExprKind::Call(err_fun, [err_arg]) = try_arg.kind
&& is_res_lang_ctor(cx, path_res(cx, err_fun), ResultErr)
&& let Some(return_ty) = find_return_type(cx, &expr.kind)
{
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/clone_on_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(super) fn check(
return;
},
// ? is a Call, makes sure not to rec *x?, but rather (*x)?
ExprKind::Call(hir_callee, _) => matches!(
ExprKind::Call(hir_callee, [_]) => matches!(
hir_callee.kind,
ExprKind::Path(QPath::LangItem(rustc_hir::LangItem::TryTraitBranch, ..))
),
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/methods/iter_filter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ fn is_method(

fn parent_is_map(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> bool {
if let Some(expr) = get_parent_expr(cx, expr)
&& is_trait_method(cx, expr, sym::Iterator)
&& let ExprKind::MethodCall(path, _, _, _) = expr.kind
&& let ExprKind::MethodCall(path, _, [_], _) = expr.kind
&& path.ident.name == sym::map
&& is_trait_method(cx, expr, sym::Iterator)
{
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/methods/manual_c_str_literals.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, func: &Expr<'_>, args

/// Checks `CStr::from_ptr(b"foo\0".as_ptr().cast())`
fn check_from_ptr(cx: &LateContext<'_>, expr: &Expr<'_>, arg: &Expr<'_>) {
if let ExprKind::MethodCall(method, lit, ..) = peel_ptr_cast(arg).kind
if let ExprKind::MethodCall(method, lit, [], _) = peel_ptr_cast(arg).kind
&& method.ident.name == sym::as_ptr
&& !lit.span.from_expansion()
&& let ExprKind::Lit(lit) = lit.kind
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/methods/manual_saturating_arithmetic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ enum MinMax {

fn is_min_or_max(cx: &LateContext<'_>, expr: &hir::Expr<'_>) -> Option<MinMax> {
// `T::max_value()` `T::min_value()` inherent methods
if let hir::ExprKind::Call(func, args) = &expr.kind
&& args.is_empty()
if let hir::ExprKind::Call(func, []) = &expr.kind
&& let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind
{
match segment.ident.as_str() {
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/methods/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,8 @@ pub(super) fn check(cx: &LateContext<'_>, e: &hir::Expr<'_>, recv: &hir::Expr<'_
}
}
},
hir::ExprKind::Call(call, args) => {
hir::ExprKind::Call(call, [arg]) => {
if let hir::ExprKind::Path(qpath) = call.kind
&& let [arg] = args
&& ident_eq(name, arg)
{
handle_path(cx, call, &qpath, e, recv);
Expand Down
Loading

0 comments on commit 236751d

Please sign in to comment.