Skip to content

Commit 236751d

Browse files
committed
Auto merge of #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

59 files changed

Lines changed: 127 additions & 149 deletions

Some content is hidden

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

‎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
&& letExprKind::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-
&& letExprKind::MethodCall(method_path, receiver,..) = cast_expr.kind
22+
&& letExprKind::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-
}elseifletExprKind::MethodCall(method_path, self_arg,..) = &expr.kind{
22+
}elseifletExprKind::MethodCall(method_path, self_arg,[], _) = &expr.kind{
2323
if method_path.ident.name == sym!(cast)
2424
&& letSome(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
implLateLintPass<'_>forCreateDir{
3636
fncheck_expr(&mutself,cx:&LateContext<'_>,expr:&Expr<'_>){
37-
ifletExprKind::Call(func,[arg, ..]) = expr.kind
37+
ifletExprKind::Call(func,[arg]) = expr.kind
3838
&& letExprKind::Path(ref path) = func.kind
3939
&& letSome(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-
&& letExprKind::Call(path,..) = expr.kind
86+
&& letExprKind::Call(path,[]) = expr.kind
8787
&& !in_automatically_derived(cx.tcx, expr.hir_id)
8888
&& letExprKind::Path(ref qpath) = path.kind
8989
&& letSome(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
fnis_expr_default<'tcx>(expr:&'tcxExpr<'tcx>,cx:&LateContext<'tcx>) -> bool{
256-
ifletExprKind::Call(fn_expr,_) = &expr.kind
256+
ifletExprKind::Call(fn_expr,[]) = &expr.kind
257257
&& letExprKind::Path(qpath) = &fn_expr.kind
258258
&& letRes::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>forExit{
4545
fncheck_expr(&mutself,cx:&LateContext<'tcx>,e:&'tcxExpr<'_>){
46-
ifletExprKind::Call(path_expr,_args) = e.kind
46+
ifletExprKind::Call(path_expr,[_]) = e.kind
4747
&& letExprKind::Path(ref path) = path_expr.kind
4848
&& letSome(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
&& letExprKind::MethodCall(write_fun, write_recv,[write_arg], _) = *look_in_block(cx,&write_call.kind)
60-
&& letExprKind::Call(write_recv_path,_) = write_recv.kind
60+
&& letExprKind::Call(write_recv_path,[]) = write_recv.kind
6161
&& write_fun.ident.name == sym!(write_fmt)
6262
&& letSome(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+
&& letExprKind::MethodCall(path, self_arg,[], _) = &lhs.kind
440+
&& path.ident.name.as_str() == "exp"
439441
&& cx.typeck_results().expr_ty(lhs).is_floating_point()
440442
&& letSome(value) = ConstEvalCtxt::new(cx).eval(rhs)
441443
&& (F32(1.0) == value || F64(1.0) == value)
442-
&& letExprKind::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
implFormatImplExpr<'_,'_>{
152152
fncheck_to_string_in_display(&self){
153153
ifself.format_trait_impl.name == sym::Display
154-
&& letExprKind::MethodCall(path, self_arg,..) = self.expr.kind
154+
&& letExprKind::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:&'tcxExpr<'_>,
8383
op_mutex:Option<&'tcxExpr<'_>>,
8484
) -> ControlFlow<&'tcxExpr<'tcx>>{
85-
ifletExprKind::MethodCall(path, self_arg,..) = &expr.kind
85+
ifletExprKind::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)