Skip to content

Commit aad10bc

Browse files
oslfmtsmoelius
authored andcommitted
add more paths
1 parent 2ba14bd commit aad10bc

File tree

4 files changed

+10
-1410
lines changed

4 files changed

+10
-1410
lines changed

crate/src/paths.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,7 @@ pub const ANCHOR_LANG_SIGNER: [&str; 4] = ["anchor_lang", "accounts", "signer",
44
pub const SOLANA_PROGRAM_ACCOUNT_INFO: [&str; 3] =
55
["solana_program", "account_info", "AccountInfo"];
66
pub const BORSH_TRY_FROM_SLICE: [&str; 4] = ["borsh", "de", "BorshDeserialize", "try_from_slice"];
7-
7+
pub const ANCHOR_ACCOUNT: [&str; 4] = ["anchor_lang", "accounts", "account", "Account"];
8+
pub const ANCHOR_DISCRIMINATOR_TRAIT: [&str; 2] = ["anchor_lang", "Discriminator"];
9+
pub const ANCHOR_TRY_DESERIALIZE: [&str; 3] =
10+
["anchor_lang", "AccountDeserialize", "try_deserialize"];

lints/type_cosplay/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Furthermore, one may have alternative definitions of a discriminant, such as usi
3333
or u8, and not an enum. This will flag a false positive.
3434

3535
## Note on Tests
36+
3637
**insecure-anchor**: insecure because `User` type derives Discriminator trait (via `#[account]`),
3738
thus one may expect this code to be secure. However, the program tries to deserialize with
3839
`try_from_slice`, the default borsh deserialization method, which does _not_ check for the

lints/type_cosplay/src/lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ extern crate rustc_index;
88
extern crate rustc_middle;
99
extern crate rustc_span;
1010

11-
use clippy_utils::{diagnostics::span_lint_and_help, match_def_path, ty::implements_trait, get_trait_def_id};
11+
use clippy_utils::{
12+
diagnostics::span_lint_and_help, get_trait_def_id, match_def_path, ty::implements_trait,
13+
};
1214
use rustc_data_structures::fx::FxHashMap;
1315
use rustc_hir::{def::Res, Expr, ExprKind, QPath, TyKind};
1416
use rustc_index::vec::Idx;
@@ -89,7 +91,8 @@ impl<'tcx> LateLintPass<'tcx> for TypeCosplay {
8991
if let Some(trait_did) = get_trait_def_id(cx, &paths::ANCHOR_DISCRIMINATOR_TRAIT);
9092
then {
9193
if implements_trait(cx, middle_ty, trait_did, &[]) {
92-
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(fnc_expr.hir_id) {
94+
if let Some(def_id) = cx.typeck_results().type_dependent_def_id(fnc_expr.hir_id)
95+
{
9396
if !match_def_path(cx, def_id, &paths::ANCHOR_TRY_DESERIALIZE) {
9497
span_lint_and_help(
9598
cx,

0 commit comments

Comments
 (0)