diff --git a/crate/diffs/arbitrary_cpi.diff b/crate/diffs/arbitrary_cpi.diff index 589e357..b6c24e7 100644 --- a/crate/diffs/arbitrary_cpi.diff +++ b/crate/diffs/arbitrary_cpi.diff @@ -1,15 +1,15 @@ -diff -r ./insecure/Cargo.toml ../../../../lints/arbitrary_cpi/ui/insecure/Cargo.toml +diff -r -x Cargo.lock ./insecure/Cargo.toml ../../../../lints/arbitrary_cpi/ui/insecure/Cargo.toml 19,21c19,22 < anchor-lang = "0.20.1" < anchor-spl = "0.20.1" < spl-token = { version = "3.1.1", features = ["no-entrypoint"] } \ No newline at end of file --- -> anchor-lang = "0.25.0" -> anchor-spl = "0.25.0" +> anchor-lang = "0.29.0" +> anchor-spl = "0.29.0" > > [workspace] -diff -r ./insecure/src/lib.rs ../../../../lints/arbitrary_cpi/ui/insecure/src/lib.rs +diff -r -x Cargo.lock ./insecure/src/lib.rs ../../../../lints/arbitrary_cpi/ui/insecure/src/lib.rs 2a3,4 > use anchor_lang::solana_program::entrypoint::ProgramResult; > use anchor_spl::token::spl_token; @@ -18,18 +18,18 @@ diff -r ./insecure/src/lib.rs ../../../../lints/arbitrary_cpi/ui/insecure/src/li > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/arbitrary_cpi/ui: insecure-2 -diff -r ./recommended/Cargo.toml ../../../../lints/arbitrary_cpi/ui/recommended/Cargo.toml +diff -r -x Cargo.lock ./recommended/Cargo.toml ../../../../lints/arbitrary_cpi/ui/recommended/Cargo.toml 19,21c19,22 < anchor-lang = "0.20.1" < anchor-spl = "0.20.1" < spl-token = { version = "3.1.1", features = ["no-entrypoint"] } \ No newline at end of file --- -> anchor-lang = "0.25.0" -> anchor-spl = "0.25.0" +> anchor-lang = "0.29.0" +> anchor-spl = "0.29.0" > > [workspace] -diff -r ./recommended/src/lib.rs ../../../../lints/arbitrary_cpi/ui/recommended/src/lib.rs +diff -r -x Cargo.lock ./recommended/src/lib.rs ../../../../lints/arbitrary_cpi/ui/recommended/src/lib.rs 10c10 < pub fn cpi(ctx: Context, amount: u64) -> ProgramResult { --- @@ -38,17 +38,17 @@ diff -r ./recommended/src/lib.rs ../../../../lints/arbitrary_cpi/ui/recommended/ > > #[allow(dead_code)] > fn main() {} -diff -r ./secure/Cargo.toml ../../../../lints/arbitrary_cpi/ui/secure/Cargo.toml +diff -r -x Cargo.lock ./secure/Cargo.toml ../../../../lints/arbitrary_cpi/ui/secure/Cargo.toml 19,21c19,22 < anchor-lang = "0.20.1" < anchor-spl = "0.20.1" < spl-token = { version = "3.1.1", features = ["no-entrypoint"] } --- -> anchor-lang = "0.25.0" -> anchor-spl = "0.25.0" +> anchor-lang = "0.29.0" +> anchor-spl = "0.29.0" > > [workspace] -diff -r ./secure/src/lib.rs ../../../../lints/arbitrary_cpi/ui/secure/src/lib.rs +diff -r -x Cargo.lock ./secure/src/lib.rs ../../../../lints/arbitrary_cpi/ui/secure/src/lib.rs 2a3,4 > use anchor_lang::solana_program::entrypoint::ProgramResult; > use anchor_spl::token::spl_token; diff --git a/crate/diffs/bump_seed_canonicalization.diff b/crate/diffs/bump_seed_canonicalization.diff index 010943c..92ad316 100644 --- a/crate/diffs/bump_seed_canonicalization.diff +++ b/crate/diffs/bump_seed_canonicalization.diff @@ -1,11 +1,11 @@ -diff -r ./insecure/Cargo.toml ../../../../lints/bump_seed_canonicalization/ui/insecure/Cargo.toml +diff -r -x Cargo.lock ./insecure/Cargo.toml ../../../../lints/bump_seed_canonicalization/ui/insecure/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./insecure/src/lib.rs ../../../../lints/bump_seed_canonicalization/ui/insecure/src/lib.rs +diff -r -x Cargo.lock ./insecure/src/lib.rs ../../../../lints/bump_seed_canonicalization/ui/insecure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 30a32,34 @@ -15,28 +15,28 @@ diff -r ./insecure/src/lib.rs ../../../../lints/bump_seed_canonicalization/ui/in Only in ../../../../lints/bump_seed_canonicalization/ui/insecure/src: lib.stderr Only in ../../../../lints/bump_seed_canonicalization/ui: insecure-2 Only in ../../../../lints/bump_seed_canonicalization/ui: insecure-3 -diff -r ./recommended/Cargo.toml ../../../../lints/bump_seed_canonicalization/ui/recommended/Cargo.toml +diff -r -x Cargo.lock ./recommended/Cargo.toml ../../../../lints/bump_seed_canonicalization/ui/recommended/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./recommended/src/lib.rs ../../../../lints/bump_seed_canonicalization/ui/recommended/src/lib.rs +diff -r -x Cargo.lock ./recommended/src/lib.rs ../../../../lints/bump_seed_canonicalization/ui/recommended/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 35a37,39 > > #[allow(dead_code)] > fn main() {} -diff -r ./secure/Cargo.toml ../../../../lints/bump_seed_canonicalization/ui/secure/Cargo.toml +diff -r -x Cargo.lock ./secure/Cargo.toml ../../../../lints/bump_seed_canonicalization/ui/secure/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./secure/src/lib.rs ../../../../lints/bump_seed_canonicalization/ui/secure/src/lib.rs +diff -r -x Cargo.lock ./secure/src/lib.rs ../../../../lints/bump_seed_canonicalization/ui/secure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 38a40,42 diff --git a/crate/diffs/insecure_account_close.diff b/crate/diffs/insecure_account_close.diff index 28d3bb3..6b00bb0 100644 --- a/crate/diffs/insecure_account_close.diff +++ b/crate/diffs/insecure_account_close.diff @@ -1,11 +1,11 @@ -diff -r ./insecure/Cargo.toml ../../../../lints/insecure_account_close/ui/insecure/Cargo.toml +diff -r -x Cargo.lock ./insecure/Cargo.toml ../../../../lints/insecure_account_close/ui/insecure/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./insecure/src/lib.rs ../../../../lints/insecure_account_close/ui/insecure/src/lib.rs +diff -r -x Cargo.lock ./insecure/src/lib.rs ../../../../lints/insecure_account_close/ui/insecure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 30a32,34 @@ -13,14 +13,14 @@ diff -r ./insecure/src/lib.rs ../../../../lints/insecure_account_close/ui/insecu > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/insecure_account_close/ui/insecure/src: lib.stderr -diff -r ./insecure-still/Cargo.toml ../../../../lints/insecure_account_close/ui/insecure-still/Cargo.toml +diff -r -x Cargo.lock ./insecure-still/Cargo.toml ../../../../lints/insecure_account_close/ui/insecure-still/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./insecure-still/src/lib.rs ../../../../lints/insecure_account_close/ui/insecure-still/src/lib.rs +diff -r -x Cargo.lock ./insecure-still/src/lib.rs ../../../../lints/insecure_account_close/ui/insecure-still/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 45a47,49 @@ -28,14 +28,14 @@ diff -r ./insecure-still/src/lib.rs ../../../../lints/insecure_account_close/ui/ > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/insecure_account_close/ui/insecure-still/src: lib.stderr -diff -r ./insecure-still-still/Cargo.toml ../../../../lints/insecure_account_close/ui/insecure-still-still/Cargo.toml +diff -r -x Cargo.lock ./insecure-still-still/Cargo.toml ../../../../lints/insecure_account_close/ui/insecure-still-still/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./insecure-still-still/src/lib.rs ../../../../lints/insecure_account_close/ui/insecure-still-still/src/lib.rs +diff -r -x Cargo.lock ./insecure-still-still/src/lib.rs ../../../../lints/insecure_account_close/ui/insecure-still-still/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 45a47,49 @@ -43,14 +43,14 @@ diff -r ./insecure-still-still/src/lib.rs ../../../../lints/insecure_account_clo > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/insecure_account_close/ui/insecure-still-still/src: lib.stderr -diff -r ./recommended/Cargo.toml ../../../../lints/insecure_account_close/ui/recommended/Cargo.toml +diff -r -x Cargo.lock ./recommended/Cargo.toml ../../../../lints/insecure_account_close/ui/recommended/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./recommended/src/lib.rs ../../../../lints/insecure_account_close/ui/recommended/src/lib.rs +diff -r -x Cargo.lock ./recommended/src/lib.rs ../../../../lints/insecure_account_close/ui/recommended/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 18d18 @@ -60,14 +60,14 @@ diff -r ./recommended/src/lib.rs ../../../../lints/insecure_account_close/ui/rec > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/insecure_account_close/ui/recommended/src: lib.stderr -diff -r ./secure/Cargo.toml ../../../../lints/insecure_account_close/ui/secure/Cargo.toml +diff -r -x Cargo.lock ./secure/Cargo.toml ../../../../lints/insecure_account_close/ui/secure/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./secure/src/lib.rs ../../../../lints/insecure_account_close/ui/secure/src/lib.rs +diff -r -x Cargo.lock ./secure/src/lib.rs ../../../../lints/insecure_account_close/ui/secure/src/lib.rs 2a3 > use anchor_lang::solana_program::entrypoint::ProgramResult; 71a73,75 diff --git a/crate/diffs/missing_owner_check.diff b/crate/diffs/missing_owner_check.diff index 1b5fa71..75ce707 100644 --- a/crate/diffs/missing_owner_check.diff +++ b/crate/diffs/missing_owner_check.diff @@ -1,14 +1,14 @@ -diff -r ./insecure/Cargo.toml ../../../../lints/missing_owner_check/ui/insecure/Cargo.toml +diff -r -x Cargo.lock ./insecure/Cargo.toml ../../../../lints/missing_owner_check/ui/insecure/Cargo.toml 19,21c19,22 < anchor-lang = "0.20.1" < anchor-spl = "0.20.1" < spl-token = "3.2.0" --- -> anchor-lang = "0.25.0" -> anchor-spl = "0.25.0" +> anchor-lang = "0.29.0" +> anchor-spl = "0.29.0" > > [workspace] -diff -r ./insecure/src/lib.rs ../../../../lints/missing_owner_check/ui/insecure/src/lib.rs +diff -r -x Cargo.lock ./insecure/src/lib.rs ../../../../lints/missing_owner_check/ui/insecure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 4c5 @@ -20,17 +20,17 @@ diff -r ./insecure/src/lib.rs ../../../../lints/missing_owner_check/ui/insecure/ > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/missing_owner_check/ui/insecure/src: lib.stderr -diff -r ./recommended/Cargo.toml ../../../../lints/missing_owner_check/ui/recommended/Cargo.toml +diff -r -x Cargo.lock ./recommended/Cargo.toml ../../../../lints/missing_owner_check/ui/recommended/Cargo.toml 19,21c19,22 < anchor-lang = "0.20.1" < anchor-spl = "0.20.1" < spl-token = "3.2.0" --- -> anchor-lang = "0.25.0" -> anchor-spl = "0.25.0" +> anchor-lang = "0.29.0" +> anchor-spl = "0.29.0" > > [workspace] -diff -r ./recommended/src/lib.rs ../../../../lints/missing_owner_check/ui/recommended/src/lib.rs +diff -r -x Cargo.lock ./recommended/src/lib.rs ../../../../lints/missing_owner_check/ui/recommended/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 21a23,25 @@ -38,17 +38,17 @@ diff -r ./recommended/src/lib.rs ../../../../lints/missing_owner_check/ui/recomm > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/missing_owner_check/ui/recommended/src: lib.stderr -diff -r ./secure/Cargo.toml ../../../../lints/missing_owner_check/ui/secure/Cargo.toml +diff -r -x Cargo.lock ./secure/Cargo.toml ../../../../lints/missing_owner_check/ui/secure/Cargo.toml 19,21c19,22 < anchor-lang = "0.20.1" < anchor-spl = "0.20.1" < spl-token = "3.2.0" --- -> anchor-lang = "0.25.0" -> anchor-spl = "0.25.0" +> anchor-lang = "0.29.0" +> anchor-spl = "0.29.0" > > [workspace] -diff -r ./secure/src/lib.rs ../../../../lints/missing_owner_check/ui/secure/src/lib.rs +diff -r -x Cargo.lock ./secure/src/lib.rs ../../../../lints/missing_owner_check/ui/secure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 4c5,6 diff --git a/crate/diffs/missing_signer_check.diff b/crate/diffs/missing_signer_check.diff index 7f87fb0..d6b5f1e 100644 --- a/crate/diffs/missing_signer_check.diff +++ b/crate/diffs/missing_signer_check.diff @@ -1,11 +1,11 @@ -diff -r ./insecure/Cargo.toml ../../../../lints/missing_signer_check/ui/insecure/Cargo.toml +diff -r -x Cargo.lock ./insecure/Cargo.toml ../../../../lints/missing_signer_check/ui/insecure/Cargo.toml 19c19,21 < anchor-lang = "0.20.0" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./insecure/src/lib.rs ../../../../lints/missing_signer_check/ui/insecure/src/lib.rs +diff -r -x Cargo.lock ./insecure/src/lib.rs ../../../../lints/missing_signer_check/ui/insecure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 3a5 @@ -15,14 +15,14 @@ diff -r ./insecure/src/lib.rs ../../../../lints/missing_signer_check/ui/insecure > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/missing_signer_check/ui/insecure/src: lib.stderr -diff -r ./recommended/Cargo.toml ../../../../lints/missing_signer_check/ui/recommended/Cargo.toml +diff -r -x Cargo.lock ./recommended/Cargo.toml ../../../../lints/missing_signer_check/ui/recommended/Cargo.toml 19c19,21 < anchor-lang = "0.20.0" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./recommended/src/lib.rs ../../../../lints/missing_signer_check/ui/recommended/src/lib.rs +diff -r -x Cargo.lock ./recommended/src/lib.rs ../../../../lints/missing_signer_check/ui/recommended/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 18a20,22 @@ -30,14 +30,14 @@ diff -r ./recommended/src/lib.rs ../../../../lints/missing_signer_check/ui/recom > #[allow(dead_code)] > fn main() {} Only in ../../../../lints/missing_signer_check/ui/recommended/src: lib.stderr -diff -r ./secure/Cargo.toml ../../../../lints/missing_signer_check/ui/secure/Cargo.toml +diff -r -x Cargo.lock ./secure/Cargo.toml ../../../../lints/missing_signer_check/ui/secure/Cargo.toml 19c19,21 < anchor-lang = "0.20.0" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./secure/src/lib.rs ../../../../lints/missing_signer_check/ui/secure/src/lib.rs +diff -r -x Cargo.lock ./secure/src/lib.rs ../../../../lints/missing_signer_check/ui/secure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 21a23,25 diff --git a/crate/diffs/type_cosplay.diff b/crate/diffs/type_cosplay.diff index 3a6b7d8..4173dea 100644 --- a/crate/diffs/type_cosplay.diff +++ b/crate/diffs/type_cosplay.diff @@ -1,11 +1,11 @@ -diff -r ./insecure/Cargo.toml ../../../../lints/type_cosplay/ui/insecure/Cargo.toml +diff -r -x Cargo.lock ./insecure/Cargo.toml ../../../../lints/type_cosplay/ui/insecure/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./insecure/src/lib.rs ../../../../lints/type_cosplay/ui/insecure/src/lib.rs +diff -r -x Cargo.lock ./insecure/src/lib.rs ../../../../lints/type_cosplay/ui/insecure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 37a39,41 @@ -16,14 +16,14 @@ Only in ../../../../lints/type_cosplay/ui/insecure/src: lib.stderr Only in ../../../../lints/type_cosplay/ui: insecure-2 Only in ../../../../lints/type_cosplay/ui: insecure-3 Only in ../../../../lints/type_cosplay/ui: insecure-anchor -diff -r ./recommended/Cargo.toml ../../../../lints/type_cosplay/ui/recommended/Cargo.toml +diff -r -x Cargo.lock ./recommended/Cargo.toml ../../../../lints/type_cosplay/ui/recommended/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./recommended/src/lib.rs ../../../../lints/type_cosplay/ui/recommended/src/lib.rs +diff -r -x Cargo.lock ./recommended/src/lib.rs ../../../../lints/type_cosplay/ui/recommended/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 31a33,35 @@ -32,14 +32,14 @@ diff -r ./recommended/src/lib.rs ../../../../lints/type_cosplay/ui/recommended/s > fn main() {} Only in ../../../../lints/type_cosplay/ui/recommended/src: lib.stderr Only in ../../../../lints/type_cosplay/ui: recommended-2 -diff -r ./secure/Cargo.toml ../../../../lints/type_cosplay/ui/secure/Cargo.toml +diff -r -x Cargo.lock ./secure/Cargo.toml ../../../../lints/type_cosplay/ui/secure/Cargo.toml 19c19,21 < anchor-lang = "0.20.1" --- -> anchor-lang = "0.25.0" +> anchor-lang = "0.29.0" > > [workspace] -diff -r ./secure/src/lib.rs ../../../../lints/type_cosplay/ui/secure/src/lib.rs +diff -r -x Cargo.lock ./secure/src/lib.rs ../../../../lints/type_cosplay/ui/secure/src/lib.rs 1a2 > use anchor_lang::solana_program::entrypoint::ProgramResult; 48a50,52 diff --git a/crate/src/lib.rs b/crate/src/lib.rs index ecd10e9..17b0a41 100644 --- a/crate/src/lib.rs +++ b/crate/src/lib.rs @@ -3,6 +3,9 @@ extern crate rustc_hir; +#[allow(unused_extern_crates)] +extern crate rustc_driver; + pub mod paths; pub mod utils; diff --git a/crate/src/paths.rs b/crate/src/paths.rs index dc6f9b4..1fd7a2e 100644 --- a/crate/src/paths.rs +++ b/crate/src/paths.rs @@ -3,7 +3,8 @@ // all in upper snake case. pub const ANCHOR_LANG_ACCOUNT: [&str; 4] = ["anchor_lang", "accounts", "account", "Account"]; -pub const ANCHOR_LANG_ACCOUNT_LOADER: [&str; 4] = ["anchor_lang", "accounts", "account_loader", "AccountLoader"]; +pub const ANCHOR_LANG_ACCOUNT_LOADER: [&str; 4] = + ["anchor_lang", "accounts", "account_loader", "AccountLoader"]; pub const ANCHOR_LANG_PROGRAM: [&str; 4] = ["anchor_lang", "accounts", "program", "Program"]; pub const ANCHOR_LANG_SYSTEM_ACCOUNT: [&str; 4] = ["anchor_lang", "accounts", "system_account", "SystemAccount"]; diff --git a/crate/tests/meta.rs b/crate/tests/meta.rs index 997c890..051a42c 100644 --- a/crate/tests/meta.rs +++ b/crate/tests/meta.rs @@ -1,6 +1,9 @@ #![feature(rustc_private)] #![warn(unused_extern_crates)] +#[allow(unused_extern_crates)] +extern crate rustc_driver; + extern crate rustc_data_structures; use rustc_data_structures::fx::FxHashMap; diff --git a/lints/arbitrary_cpi/src/lib.rs b/lints/arbitrary_cpi/src/lib.rs index e5157a3..e8afd0a 100644 --- a/lints/arbitrary_cpi/src/lib.rs +++ b/lints/arbitrary_cpi/src/lib.rs @@ -86,7 +86,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitraryCpi { .. } = &t.kind; if let mir::Operand::Constant(box func) = func_operand; - if let TyKind::FnDef(def_id, _callee_substs) = func.literal.ty().kind(); + if let TyKind::FnDef(def_id, _callee_substs) = func.const_.ty().kind(); then { // Static call let callee_did = *def_id; @@ -160,7 +160,7 @@ impl ArbitraryCpi { && !found_program_id => { if_chain! { - if let TyKind::FnDef(def_id, _callee_substs) = func.literal.ty().kind(); + if let TyKind::FnDef(def_id, _callee_substs) = func.const_.ty().kind(); if !args.is_empty(); if let Operand::Copy(arg0_pl) | Operand::Move(arg0_pl) = &args[0]; then { @@ -325,7 +325,7 @@ impl ArbitraryCpi { .. } = &t.kind; if let mir::Operand::Constant(box func) = func_operand; - if let TyKind::FnDef(def_id, _callee_substs) = func.literal.ty().kind(); + if let TyKind::FnDef(def_id, _callee_substs) = func.const_.ty().kind(); if match_def_path(cx, *def_id, &["core", "cmp", "PartialEq", "ne"]) || match_def_path(cx, *def_id, &["core", "cmp", "PartialEq", "eq"]); if let Operand::Copy(arg0_pl) | Operand::Move(arg0_pl) = args[0]; @@ -338,10 +338,7 @@ impl ArbitraryCpi { { // we found the check. if it dominates the call to invoke, then the check // is assumed to be sufficient! - return body - .basic_blocks - .dominators() - .is_dominated_by(block, cur_block); + return body.basic_blocks.dominators().dominates(cur_block, block); } } } diff --git a/lints/arbitrary_cpi/ui/insecure-2/src/lib.stderr b/lints/arbitrary_cpi/ui/insecure-2/src/lib.stderr index acdae1c..38c26a5 100644 --- a/lints/arbitrary_cpi/ui/insecure-2/src/lib.stderr +++ b/lints/arbitrary_cpi/ui/insecure-2/src/lib.stderr @@ -11,6 +11,7 @@ LL | | ) | |_________^ | = note: `-D arbitrary-cpi` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(arbitrary_cpi)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/bump_seed_canonicalization/src/lib.rs b/lints/bump_seed_canonicalization/src/lib.rs index 710107e..f0ecd7d 100644 --- a/lints/bump_seed_canonicalization/src/lib.rs +++ b/lints/bump_seed_canonicalization/src/lib.rs @@ -17,10 +17,12 @@ use rustc_middle::{ ty::Ty, ty::TyKind, }; +use rustc_target::abi::FieldIdx; use solana_lints::paths; extern crate rustc_hir; extern crate rustc_middle; +extern crate rustc_target; dylint_linting::declare_late_lint! { /// **What it does:** @@ -56,18 +58,17 @@ impl<'tcx> LateLintPass<'tcx> for BumpSeedCanonicalization { .basic_blocks .iter_enumerated() .map(|(block_id, block)| (block_id, &block.terminator)); - for (_idx, (block_id, terminator)) in terminators.enumerate() { + for (block_id, terminator) in terminators { if_chain! { if let t = terminator.as_ref().unwrap(); if let TerminatorKind::Call { func: func_operand, args, destination: _, - cleanup: _, .. } = &t.kind; if let mir::Operand::Constant(box func) = func_operand; - if let TyKind::FnDef(def_id, _callee_substs) = func.literal.ty().kind(); + if let TyKind::FnDef(def_id, _callee_substs) = func.const_.ty().kind(); then { // Static call let callee_did = *def_id; @@ -209,14 +210,15 @@ impl BumpSeedCanonicalization { Rvalue::Aggregate(box AggregateKind::Array(_), elements) => match state { BackwardDataflowState::SeedsArray if elements.len() > 1 => { - if let Operand::Move(pl) = elements.last().unwrap() { + if let Operand::Move(pl) = elements.into_iter().last().unwrap() + { seeds_arg = pl; state = BackwardDataflowState::FirstSeed; } } BackwardDataflowState::FirstSeed if elements.len() == 1 => { - if let Operand::Move(pl) = &elements[0] { - seeds_arg = pl; + if let Operand::Move(pl) = &elements[FieldIdx::from_u32(0)] { + seeds_arg = &pl; likely_bump_seed_aliases.push(*seeds_arg); state = BackwardDataflowState::Bump; } diff --git a/lints/bump_seed_canonicalization/ui/insecure-2/src/lib.stderr b/lints/bump_seed_canonicalization/ui/insecure-2/src/lib.stderr index f9f4fbf..94d5fa0 100644 --- a/lints/bump_seed_canonicalization/ui/insecure-2/src/lib.stderr +++ b/lints/bump_seed_canonicalization/ui/insecure-2/src/lib.stderr @@ -9,6 +9,7 @@ LL | | )?; | |_________^ | = note: `-D bump-seed-canonicalization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(bump_seed_canonicalization)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/bump_seed_canonicalization/ui/insecure-3/src/lib.stderr b/lints/bump_seed_canonicalization/ui/insecure-3/src/lib.stderr index df7a04b..b2287e7 100644 --- a/lints/bump_seed_canonicalization/ui/insecure-3/src/lib.stderr +++ b/lints/bump_seed_canonicalization/ui/insecure-3/src/lib.stderr @@ -9,6 +9,7 @@ LL | | )?; | |_________^ | = note: `-D bump-seed-canonicalization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(bump_seed_canonicalization)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/bump_seed_canonicalization/ui/insecure/src/lib.stderr b/lints/bump_seed_canonicalization/ui/insecure/src/lib.stderr index 74effc0..9fe3e18 100644 --- a/lints/bump_seed_canonicalization/ui/insecure/src/lib.stderr +++ b/lints/bump_seed_canonicalization/ui/insecure/src/lib.stderr @@ -5,6 +5,7 @@ LL | Pubkey::create_program_address(&[key.to_le_bytes().as_ref(), &[ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D bump-seed-canonicalization` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(bump_seed_canonicalization)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/insecure_account_close/src/lib.rs b/lints/insecure_account_close/src/lib.rs index 9c721f9..120b799 100644 --- a/lints/insecure_account_close/src/lib.rs +++ b/lints/insecure_account_close/src/lib.rs @@ -82,9 +82,9 @@ fn is_initial_eight_byte_copy_from_slice(expr: &Expr<'_>) -> bool { if method_name.ident.as_str() == "copy_from_slice"; if let [arg] = args; if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, inner) = arg.kind; - if let ExprKind::Index(_, index) = inner.kind; + if let ExprKind::Index(_, index, _) = inner.kind; if let ExprKind::Struct(qpath, fields, None) = index.kind; - if matches!(qpath, QPath::LangItem(LangItem::Range, _, _)); + if matches!(qpath, QPath::LangItem(LangItem::Range, _)); if let [start, end] = fields; if let ExprKind::Lit(ref start_lit) = start.expr.kind; if let LitKind::Int(0, LitIntType::Unsuffixed) = start_lit.node; @@ -126,7 +126,7 @@ fn is_eight_byte_array<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'tcx>) -> bool if_chain! { if let TyKind::Array(ty, length) = ty.kind(); if *ty.kind() == TyKind::Uint(UintTy::U8); - if let Some(length) = length.try_eval_usize(cx.tcx, cx.param_env); + if let Some(length) = length.try_eval_target_usize(cx.tcx, cx.param_env); if length == 8; then { true diff --git a/lints/insecure_account_close/ui/insecure/src/lib.stderr b/lints/insecure_account_close/ui/insecure/src/lib.stderr index 341fc48..85a9848 100644 --- a/lints/insecure_account_close/ui/insecure/src/lib.stderr +++ b/lints/insecure_account_close/ui/insecure/src/lib.stderr @@ -5,6 +5,7 @@ LL | **ctx.accounts.account.to_account_info().lamports.borrow_mut() = 0; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = note: `-D insecure-account-close` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(insecure_account_close)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/missing_owner_check/src/lib.rs b/lints/missing_owner_check/src/lib.rs index 65de085..9916796 100644 --- a/lints/missing_owner_check/src/lib.rs +++ b/lints/missing_owner_check/src/lib.rs @@ -10,8 +10,9 @@ use clippy_utils::{ }; use if_chain::if_chain; use rustc_hir::{ + def_id::LocalDefId, intravisit::{walk_expr, FnKind, Visitor}, - Body, Expr, ExprKind, FnDecl, HirId, + Body, Expr, ExprKind, FnDecl, }; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty; @@ -65,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for MissingOwnerCheck { _: &'tcx FnDecl<'tcx>, body: &'tcx Body<'tcx>, span: Span, - _: HirId, + _: LocalDefId, ) { if !span.from_expansion() { let accounts = get_referenced_accounts(cx, body); @@ -135,7 +136,7 @@ fn is_call_to_clone<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> boo // smoelius: See: https://github.com/crytic/solana-lints/issues/31 fn is_safe_to_account_info<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -> bool { if_chain! { - if let Some(recv) = is_to_account_info(cx, expr); + if let Some(recv) = is_to_account_info(cx, expr); if let ty::Ref(_, recv_ty, _) = cx.typeck_results().expr_ty_adjusted(recv).kind(); if let ty::Adt(adt_def, _) = recv_ty.kind(); // smoelius: diff --git a/lints/missing_owner_check/ui/insecure/src/lib.stderr b/lints/missing_owner_check/ui/insecure/src/lib.stderr index f80a860..1b1accb 100644 --- a/lints/missing_owner_check/ui/insecure/src/lib.stderr +++ b/lints/missing_owner_check/ui/insecure/src/lib.stderr @@ -5,6 +5,7 @@ LL | let token = SplTokenAccount::unpack(&ctx.accounts.token.data.borrow | ^^^^^^^^^^^^^^^^^^ | = note: `-D missing-owner-check` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(missing_owner_check)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/missing_signer_check/src/lib.rs b/lints/missing_signer_check/src/lib.rs index 932ebcc..14becd9 100644 --- a/lints/missing_signer_check/src/lib.rs +++ b/lints/missing_signer_check/src/lib.rs @@ -7,12 +7,9 @@ extern crate rustc_span; use clippy_utils::{diagnostics::span_lint, ty::match_type}; use if_chain::if_chain; -use rustc_hir::{intravisit::FnKind, Body, Expr, ExprKind, FnDecl, HirId}; +use rustc_hir::{def_id::LocalDefId, intravisit::FnKind, Body, Expr, ExprKind, FnDecl}; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{ - self, - subst::{GenericArg, GenericArgKind}, -}; +use rustc_middle::ty::{self, GenericArg, GenericArgKind}; use rustc_span::Span; use solana_lints::{paths, utils::visit_expr_no_bodies}; @@ -47,12 +44,12 @@ impl<'tcx> LateLintPass<'tcx> for MissingSignerCheck { _: &'tcx FnDecl<'tcx>, body: &'tcx Body<'tcx>, span: Span, - hir_id: HirId, + local_def_id: LocalDefId, ) { if_chain! { if matches!(fn_kind, FnKind::ItemFn(..)); if body_uses_account_info(cx, body); - if !context_contains_signer_field(cx, hir_id); + if !context_contains_signer_field(cx, local_def_id); if !body_contains_is_signer_use(cx, body); then { span_lint( @@ -73,9 +70,12 @@ fn body_uses_account_info<'tcx>(cx: &LateContext<'tcx>, body: &'tcx Body<'tcx>) }) } -fn context_contains_signer_field(cx: &LateContext<'_>, hir_id: HirId) -> bool { - let local_def_id = cx.tcx.hir().local_def_id(hir_id); - let fn_sig = cx.tcx.fn_sig(local_def_id.to_def_id()).skip_binder(); +fn context_contains_signer_field(cx: &LateContext<'_>, local_def_id: LocalDefId) -> bool { + let fn_sig = cx + .tcx + .fn_sig(local_def_id.to_def_id()) + .skip_binder() + .skip_binder(); if_chain! { if let Some(ty) = fn_sig .inputs() diff --git a/lints/missing_signer_check/ui/insecure/src/lib.stderr b/lints/missing_signer_check/ui/insecure/src/lib.stderr index a6e22e6..ef7baf6 100644 --- a/lints/missing_signer_check/ui/insecure/src/lib.stderr +++ b/lints/missing_signer_check/ui/insecure/src/lib.stderr @@ -8,6 +8,7 @@ LL | | } | |_____^ | = note: `-D missing-signer-check` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(missing_signer_check)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/type_cosplay/src/lib.rs b/lints/type_cosplay/src/lib.rs index d0a99ee..fcf8a15 100644 --- a/lints/type_cosplay/src/lib.rs +++ b/lints/type_cosplay/src/lib.rs @@ -7,6 +7,7 @@ extern crate rustc_hir; extern crate rustc_index; extern crate rustc_middle; extern crate rustc_span; +extern crate rustc_target; use clippy_utils::{ diagnostics::span_lint_and_help, @@ -16,10 +17,12 @@ use clippy_utils::{ use if_chain::if_chain; use rustc_data_structures::fx::FxHashMap; use rustc_hir::{def::Res, Expr, ExprKind, QPath, TyKind}; -use rustc_index::vec::Idx; +use rustc_index::Idx; use rustc_lint::{LateContext, LateLintPass}; -use rustc_middle::ty::{AdtDef, AdtKind, TyKind as MiddleTyKind}; +use rustc_middle::ty::{AdtDef, TyKind as MiddleTyKind}; +use rustc_session::DataTypeKind; use rustc_span::{def_id::DefId, Span}; +use rustc_target::abi::FieldIdx; use solana_lints::{paths, utils::visit_expr_no_bodies}; dylint_linting::impl_late_lint! { @@ -140,7 +143,7 @@ dylint_linting::impl_late_lint! { #[derive(Default)] struct TypeCosplay { - deser_types: FxHashMap>, + deser_types: FxHashMap>, } impl<'tcx> LateLintPass<'tcx> for TypeCosplay { @@ -162,7 +165,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeCosplay { if let TyKind::Path(ty_qpath) = &ty.kind; let res = cx.typeck_results().qpath_res(ty_qpath, ty.hir_id); if let Res::Def(_, def_id) = res; - let middle_ty = cx.tcx.type_of(def_id); + let middle_ty = cx.tcx.type_of(def_id).skip_binder(); then { if_chain! { if let Some(trait_did) = get_trait_def_id(cx, &paths::ANCHOR_LANG_DISCRIMINATOR); @@ -186,10 +189,10 @@ impl<'tcx> LateLintPass<'tcx> for TypeCosplay { if let MiddleTyKind::Adt(adt_def, _) = middle_ty.kind() { let adt_kind = adt_def.adt_kind(); let def_id = adt_def.did(); - if let Some(vec) = self.deser_types.get_mut(&adt_kind) { + if let Some(vec) = self.deser_types.get_mut(&adt_kind.into()) { vec.push((def_id, ty.span)); } else { - self.deser_types.insert(adt_kind, vec![(def_id, ty.span)]); + self.deser_types.insert(adt_kind.into(), vec![(def_id, ty.span)]); } } } @@ -205,7 +208,7 @@ impl<'tcx> LateLintPass<'tcx> for TypeCosplay { if self.deser_types.len() == 1 { let (k, v) = self.deser_types.iter().next().unwrap(); match k { - AdtKind::Enum => check_enums(cx, v), + DataTypeKind::Enum => check_enums(cx, v), _ => check_structs_have_discriminant(cx, v), // NOTE: also catches unions } } else if self.deser_types.len() > 1 { @@ -279,8 +282,8 @@ fn check_structs_have_discriminant(cx: &LateContext<'_>, types: &Vec<(DefId, Spa /// be the first field in the adt. fn has_discriminant(cx: &LateContext, adt: AdtDef, num_struct_types: usize, span: Span) { let variant = adt.variants().get(Idx::new(0)).unwrap(); - let first_field_def = &variant.fields[0]; - let ty = cx.tcx.type_of(first_field_def.did); + let first_field_def = &variant.fields[FieldIdx::new(0)]; + let ty = cx.tcx.type_of(first_field_def.did).skip_binder(); if_chain! { if let MiddleTyKind::Adt(adt_def, _) = ty.kind(); if adt_def.is_enum(); diff --git a/lints/type_cosplay/ui/insecure-2/src/lib.stderr b/lints/type_cosplay/ui/insecure-2/src/lib.stderr index a152a1e..089f11c 100644 --- a/lints/type_cosplay/ui/insecure-2/src/lib.stderr +++ b/lints/type_cosplay/ui/insecure-2/src/lib.stderr @@ -10,6 +10,7 @@ help: consider constructing a single enum that contains all type definitions as LL | let metadata = MetadataInfo::try_from_slice(&ctx.accounts.user.data.borrow()).unwrap(); | ^^^^^^^^^^^^ = note: `-D type-cosplay` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(type_cosplay)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/type_cosplay/ui/insecure-3/src/lib.stderr b/lints/type_cosplay/ui/insecure-3/src/lib.stderr index 0601964..8058225 100644 --- a/lints/type_cosplay/ui/insecure-3/src/lib.stderr +++ b/lints/type_cosplay/ui/insecure-3/src/lib.stderr @@ -10,6 +10,7 @@ help: deserialize from only structs with a discriminant, or an enum encapsulatin LL | AccountWithDiscriminant::try_from_slice(&ctx.accounts.user.data.borrow()).unwrap(); | ^^^^^^^^^^^^^^^^^^^^^^^ = note: `-D type-cosplay` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(type_cosplay)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/type_cosplay/ui/insecure-anchor/src/lib.stderr b/lints/type_cosplay/ui/insecure-anchor/src/lib.stderr index 7a022c1..8e13e73 100644 --- a/lints/type_cosplay/ui/insecure-anchor/src/lib.stderr +++ b/lints/type_cosplay/ui/insecure-anchor/src/lib.stderr @@ -7,6 +7,7 @@ LL | let user = User::try_from_slice(&ctx.accounts.user.data.borrow()).u | = help: otherwise, make sure you are accounting for this type's discriminator in your deserialization function = note: `-D type-cosplay` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(type_cosplay)]` -error: aborting due to previous error +error: aborting due to 1 previous error diff --git a/lints/type_cosplay/ui/insecure/src/lib.stderr b/lints/type_cosplay/ui/insecure/src/lib.stderr index 5fea49e..0aeab5a 100644 --- a/lints/type_cosplay/ui/insecure/src/lib.stderr +++ b/lints/type_cosplay/ui/insecure/src/lib.stderr @@ -6,6 +6,7 @@ LL | let user = User::try_from_slice(&ctx.accounts.user.data.borrow()).u | = help: add an enum with at least as many variants as there are struct definitions = note: `-D type-cosplay` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(type_cosplay)]` -error: aborting due to previous error +error: aborting due to 1 previous error