From 874d9e8d6e9b436f2dbd1089fbfba7292ad39d29 Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Fri, 19 Jan 2024 08:08:43 -0300 Subject: [PATCH 1/2] chore(tests): Fix clippy warnings --- linting/extra/ui/pass/non_fallible_api.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linting/extra/ui/pass/non_fallible_api.rs b/linting/extra/ui/pass/non_fallible_api.rs index 4380b7de97..8d59725d63 100644 --- a/linting/extra/ui/pass/non_fallible_api.rs +++ b/linting/extra/ui/pass/non_fallible_api.rs @@ -57,9 +57,9 @@ pub mod non_fallible_api { // StorageVec let _ = self.vec_1.try_peek(); let _ = self.vec_1.try_get(0); - self.vec_1.try_set(0, &a); + let _ = self.vec_1.try_set(0, &a); let _ = self.vec_1.try_pop(); - self.vec_1.try_push(&a); + let _ = self.vec_1.try_push(&a); } // Don't raise warnings when using non-fallible API with argument which encoded From c2847fc6c1657fa963b0d509c505f577b77d6858 Mon Sep 17 00:00:00 2001 From: Georgiy Komarov Date: Fri, 19 Jan 2024 09:30:10 -0300 Subject: [PATCH 2/2] feat: Update toolchain version --- linting/extra/Cargo.toml | 4 ++-- linting/extra/src/non_fallible_api.rs | 2 +- linting/extra/src/storage_never_freed.rs | 6 +++--- linting/extra/src/strict_balance_equality.rs | 19 +++++++++---------- linting/extra/ui/fail/non_fallible_api.stderr | 1 + linting/extra/ui/fail/primitive_topic.stderr | 1 + .../ui/fail/strict_balance_equality.stderr | 1 + linting/mandatory/Cargo.toml | 4 ++-- linting/rust-toolchain.toml | 2 +- linting/utils/Cargo.toml | 2 +- linting/utils/src/lib.rs | 2 +- 11 files changed, 23 insertions(+), 21 deletions(-) diff --git a/linting/extra/Cargo.toml b/linting/extra/Cargo.toml index 2cf9797fb7..538b6da0a3 100644 --- a/linting/extra/Cargo.toml +++ b/linting/extra/Cargo.toml @@ -17,7 +17,7 @@ include = ["Cargo.toml", "*.rs", "LICENSE"] crate-type = ["cdylib"] [dependencies] -dylint_linting = "2.1.12" +dylint_linting = "2.6.0" if_chain = "1.0.2" log = "0.4.14" regex = "1.5.4" @@ -25,7 +25,7 @@ ink_linting_utils = { workspace = true } ink_env = { version = "=5.0.0-rc", path = "../../crates/env", default-features = false } [dev-dependencies] -dylint_testing = "2.1.12" +dylint_testing = "2.6.0" # The ink! dependencies used to build the `ui` tests and to compile the linting # library with `--default-features=std` (see the `features` section bellow). diff --git a/linting/extra/src/non_fallible_api.rs b/linting/extra/src/non_fallible_api.rs index 24a5ff1e35..74b3e2c16c 100644 --- a/linting/extra/src/non_fallible_api.rs +++ b/linting/extra/src/non_fallible_api.rs @@ -55,7 +55,7 @@ use rustc_session::{ declare_lint, declare_lint_pass, }; -use rustc_type_ir::sty::TyKind; +use rustc_type_ir::ty_kind::TyKind; declare_lint! { /// ## What it does diff --git a/linting/extra/src/storage_never_freed.rs b/linting/extra/src/storage_never_freed.rs index 67f56ae7c2..6fb0fffac8 100644 --- a/linting/extra/src/storage_never_freed.rs +++ b/linting/extra/src/storage_never_freed.rs @@ -168,7 +168,7 @@ fn find_collection_def_id( if_chain! { if let Res::Def(DefKind::TyAlias, def_id) = path.res; if let Some(local_id) = def_id.as_local(); - if let Some(alias_ty) = cx.tcx.hir().get_by_def_id(local_id).alias_ty(); + if let Some(alias_ty) = cx.tcx.hir_node_by_def_id(local_id).alias_ty(); if let TyKind::Path(QPath::Resolved(_, path)) = alias_ty.kind; then { return find_collection_def_id(cx, path); } }; @@ -214,7 +214,7 @@ fn find_collection_fields(cx: &LateContext, storage_struct_id: ItemId) -> Fields /// Reports the given field definition fn report_field(cx: &LateContext, field_info: &FieldInfo) { if_chain! { - if let Node::Field(field) = cx.tcx.hir().get_by_def_id(field_info.did); + if let Node::Field(field) = cx.tcx.hir_node_by_def_id(field_info.did); if !is_lint_allowed(cx, STORAGE_NEVER_FREED, field.hir_id); then { span_lint_and_help( @@ -257,7 +257,7 @@ impl<'hir> Visitor<'hir> for InsertRemoveCollector<'_> { match &e.kind { ExprKind::Assign(lhs, ..) => { if_chain! { - if let ExprKind::Index(field, _) = lhs.kind; + if let ExprKind::Index(field, _, _) = lhs.kind; if let Some(field_name) = self.find_field_name(field); then { self.fields diff --git a/linting/extra/src/strict_balance_equality.rs b/linting/extra/src/strict_balance_equality.rs index 4a86527e07..9a3d480dbd 100644 --- a/linting/extra/src/strict_balance_equality.rs +++ b/linting/extra/src/strict_balance_equality.rs @@ -42,7 +42,8 @@ use rustc_middle::{ BinOp, Body, BorrowKind, - Constant, + CallReturnPlaces, + ConstOperand, HasLocalDecls, Local, Location, @@ -51,6 +52,7 @@ use rustc_middle::{ Rvalue, Statement, Terminator, + TerminatorEdges, TerminatorKind, }, ty as mir_ty, @@ -58,8 +60,6 @@ use rustc_middle::{ use rustc_mir_dataflow::{ Analysis, AnalysisDomain, - CallReturnPlaces, - Forward, }; use rustc_session::{ declare_lint, @@ -224,8 +224,6 @@ impl<'a, 'tcx> AnalysisDomain<'tcx> for StrictBalanceEqualityAnalysis<'a, 'tcx> const NAME: &'static str = "strict_balance_equality"; - type Direction = Forward; - fn bottom_value(&self, body: &Body) -> Self::Domain { // bottom = no balance taints BitSet::new_empty(body.local_decls().len()) @@ -262,12 +260,12 @@ impl<'a, 'tcx> Analysis<'tcx> for StrictBalanceEqualityAnalysis<'a, 'tcx> { .visit_statement(statement, location); } - fn apply_terminator_effect( + fn apply_terminator_effect<'mir>( &mut self, state: &mut Self::Domain, - terminator: &Terminator, + terminator: &'mir Terminator<'tcx>, location: Location, - ) { + ) -> TerminatorEdges<'mir, 'tcx> { TransferFunction::new( self.cx, self.fun_cache, @@ -275,6 +273,7 @@ impl<'a, 'tcx> Analysis<'tcx> for StrictBalanceEqualityAnalysis<'a, 'tcx> { &mut self.mutable_references, ) .visit_terminator(terminator, location); + terminator.edges() } fn apply_call_return_effect( @@ -422,7 +421,7 @@ impl<'tcx> TransferFunction<'_, 'tcx> { fn_def_id.is_local() } - fn visit_call(&mut self, func: &Constant, args: &[Operand], destination: &Place) { + fn visit_call(&mut self, func: &ConstOperand, args: &[Operand], destination: &Place) { let init_taints = args.iter().fold(Vec::new(), |mut acc, arg| { if let Operand::Move(place) | Operand::Copy(place) = arg { acc.push(self.state.contains(place.local)) @@ -431,7 +430,7 @@ impl<'tcx> TransferFunction<'_, 'tcx> { }); let fn_def_id = - if let mir_ty::TyKind::FnDef(fn_def_id, _) = func.literal.ty().kind() { + if let mir_ty::TyKind::FnDef(fn_def_id, _) = func.const_.ty().kind() { fn_def_id } else { return diff --git a/linting/extra/ui/fail/non_fallible_api.stderr b/linting/extra/ui/fail/non_fallible_api.stderr index 134da1cb39..ea2499b818 100644 --- a/linting/extra/ui/fail/non_fallible_api.stderr +++ b/linting/extra/ui/fail/non_fallible_api.stderr @@ -5,6 +5,7 @@ LL | let _ = self.map_1.insert(a.clone(), &b); | ^^^^^^ help: consider using `try_insert` | = note: `-D non-fallible-api` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(non_fallible_api)]` error: using a non-fallible `Mapping::get` with an argument that may not fit into the static buffer --> $DIR/non_fallible_api.rs:48:32 diff --git a/linting/extra/ui/fail/primitive_topic.stderr b/linting/extra/ui/fail/primitive_topic.stderr index 6fcf4c5efc..071072be2f 100644 --- a/linting/extra/ui/fail/primitive_topic.stderr +++ b/linting/extra/ui/fail/primitive_topic.stderr @@ -5,6 +5,7 @@ LL | value_1: u8, | ^^^^^^^^^^^ help: consider removing `#[ink(topic)]`: `value_1: u8` | = note: `-D primitive-topic` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(primitive_topic)]` error: using `#[ink(topic)]` for a field with a primitive number type --> $DIR/primitive_topic.rs:16:9 diff --git a/linting/extra/ui/fail/strict_balance_equality.stderr b/linting/extra/ui/fail/strict_balance_equality.stderr index ee67592ef7..8e7593cc28 100644 --- a/linting/extra/ui/fail/strict_balance_equality.stderr +++ b/linting/extra/ui/fail/strict_balance_equality.stderr @@ -5,6 +5,7 @@ LL | if self.env().balance() == 10 { /* ... */ } | ^^^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using non-strict equality operators instead: `<`, `>` | = note: `-D strict-balance-equality` implied by `-D warnings` + = help: to override `-D warnings` add `#[allow(strict_balance_equality)]` error: dangerous strict balance equality --> $DIR/strict_balance_equality.rs:60:16 diff --git a/linting/mandatory/Cargo.toml b/linting/mandatory/Cargo.toml index 753dc39b0f..0d11900de9 100644 --- a/linting/mandatory/Cargo.toml +++ b/linting/mandatory/Cargo.toml @@ -17,14 +17,14 @@ include = ["Cargo.toml", "*.rs", "LICENSE"] crate-type = ["cdylib"] [dependencies] -dylint_linting = "2.1.12" +dylint_linting = "2.6.0" if_chain = "1.0.2" log = "0.4.14" regex = "1.5.4" ink_linting_utils = { workspace = true } [dev-dependencies] -dylint_testing = "2.1.12" +dylint_testing = "2.6.0" # The ink! dependencies used to build the `ui` tests and to compile the linting # library with `--default-features=std` (see the `features` section bellow). diff --git a/linting/rust-toolchain.toml b/linting/rust-toolchain.toml index cac65e4fce..19e193e3ff 100644 --- a/linting/rust-toolchain.toml +++ b/linting/rust-toolchain.toml @@ -2,5 +2,5 @@ # https://github.com/trailofbits/dylint/blob/ef7210cb08aac920c18d2141604efe210029f2a2/internal/template/rust-toolchain [toolchain] -channel = "nightly-2023-07-14" +channel = "nightly-2023-12-28" components = ["llvm-tools-preview", "rustc-dev"] diff --git a/linting/utils/Cargo.toml b/linting/utils/Cargo.toml index 59f6a16c1e..de72bd6dca 100644 --- a/linting/utils/Cargo.toml +++ b/linting/utils/Cargo.toml @@ -15,7 +15,7 @@ include = ["Cargo.toml", "*.rs", "LICENSE"] [dependencies] if_chain = "1.0.2" -parity_clippy_utils = "0.1.73" +parity_clippy_utils = { package = "clippy_utils", git = "https://github.com/rust-lang/rust-clippy", rev = "3fceca23bb64e304df56b3bd86d26790b5301bdf" } [package.metadata.rust-analyzer] rustc_private = true diff --git a/linting/utils/src/lib.rs b/linting/utils/src/lib.rs index 117884b862..dab32cc36c 100644 --- a/linting/utils/src/lib.rs +++ b/linting/utils/src/lib.rs @@ -75,7 +75,7 @@ pub fn find_storage_struct(cx: &LateContext, item_ids: &[ItemId]) -> Option, id: &ItemId) -> Vec { if_chain! { - if let ItemKind::Const(ty, body_id) = cx.tcx.hir().item(*id).kind; + if let ItemKind::Const(ty, _, body_id) = cx.tcx.hir().item(*id).kind; if let TyKind::Tup([]) = ty.kind; let body = cx.tcx.hir().body(body_id); if let ExprKind::Block(block, _) = body.value.kind;