diff --git a/lints/missing_owner_check/src/lib.rs b/lints/missing_owner_check/src/lib.rs index 6bba60e..ba0f62b 100644 --- a/lints/missing_owner_check/src/lib.rs +++ b/lints/missing_owner_check/src/lib.rs @@ -12,7 +12,7 @@ use if_chain::if_chain; use rustc_hir::{ def_id::LocalDefId, intravisit::{walk_expr, FnKind, Visitor}, - Body, Expr, ExprKind, FnDecl, QPath, BinOpKind, + BinOpKind, Body, Expr, ExprKind, FnDecl, QPath, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; @@ -71,7 +71,9 @@ impl<'tcx> LateLintPass<'tcx> for MissingOwnerCheck { if !span.from_expansion() { let accounts = get_referenced_accounts(cx, body); for account_expr in accounts { - if !contains_owner_use(cx, body, account_expr) && !contains_key_check(cx, body, account_expr) { + if !contains_owner_use(cx, body, account_expr) + && !contains_key_check(cx, body, account_expr) + { span_lint( cx, MISSING_OWNER_CHECK, @@ -107,7 +109,7 @@ impl<'cx, 'tcx> Visitor<'tcx> for AccountUses<'cx, 'tcx> { if_chain! { // s3v3ru5: the following check removes duplicate warnings where lint would report both `x` and `x.clone()` expressions. // ignore `clone()` expressions - if !is_expr_method_call(self.cx, expr, &paths::CORE_CLONE).is_some(); + if is_expr_method_call(self.cx, expr, &paths::CORE_CLONE).is_none(); let ty = self.cx.typeck_results().expr_ty(expr); if match_type(self.cx, ty, &paths::SOLANA_PROGRAM_ACCOUNT_INFO); if !is_expr_local_variable(expr); @@ -144,7 +146,7 @@ fn is_expr_local_variable<'tcx>(expr: &'tcx Expr<'tcx>) -> bool { fn is_safe_to_account_info<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { // is the expression method call `to_account_info()` - if let Some(recv) = is_expr_method_call(cx, expr, &paths::ANCHOR_LANG_TO_ACCOUNT_INFO); + if let Some(recv) = is_expr_method_call(cx, expr, &paths::ANCHOR_LANG_TO_ACCOUNT_INFO); if let ty::Ref(_, recv_ty, _) = cx.typeck_results().expr_ty_adjusted(recv).kind(); if let ty::Adt(adt_def, _) = recv_ty.kind(); // smoelius: @@ -202,7 +204,9 @@ fn contains_owner_use<'tcx>( body: &'tcx Body<'tcx>, account_expr: &Expr<'tcx>, ) -> bool { - visit_expr_no_bodies(body.value, |expr| uses_given_field(cx, expr, account_expr, "owner")) + visit_expr_no_bodies(body.value, |expr| { + uses_given_field(cx, expr, account_expr, "owner") + }) } /// Checks if `expr` is references `field` on `account_expr` @@ -247,7 +251,6 @@ fn calls_method_on_expr<'tcx>( } } - // Return true if the expr access key of account_expr(AccountInfo) fn expr_accesses_key<'tcx>( cx: &LateContext<'tcx>, @@ -255,7 +258,8 @@ fn expr_accesses_key<'tcx>( account_expr: &Expr<'tcx>, ) -> bool { // Anchor AccountInfo: `.key()` and Solana AccountInfo: `.key` field. - calls_method_on_expr(cx, expr, account_expr, &paths::ANCHOR_LANG_KEY) || uses_given_field(cx, expr, account_expr, "key") + calls_method_on_expr(cx, expr, account_expr, &paths::ANCHOR_LANG_KEY) + || uses_given_field(cx, expr, account_expr, "key") } fn contains_key_check<'tcx>(